Skip to content

Commit e14fec3

Browse files
authored
Merge pull request #362 from rbreesems/update_june2024
Update june2024
2 parents f0457b2 + 6fd5a60 commit e14fec3

27 files changed

+2010
-40
lines changed

src/Ghosts.Client/Handlers/SocialHelper.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Linq;
1616
using System.Collections.Generic;
1717
using Ghosts.Client.Infrastructure;
18+
using System.Web.UI.WebControls;
1819

1920

2021

@@ -118,9 +119,32 @@ public override bool DoPost(TimelineHandler handler, string action)
118119
Thread.Sleep(500);
119120
if (action == "postWimage"){
120121
// get the image file
121-
string[] imageFiles = Directory.GetFiles(postDirectory, "image*.png");
122-
if (imageFiles.Length > 0){
123-
string imageFile = imageFiles[(_random.Next(0, imageFiles.Length))];
122+
string[] imageFilesPng = Directory.GetFiles(postDirectory, "image*.png");
123+
string[] imageFilesJpg = Directory.GetFiles(postDirectory, "image*.jpg");
124+
125+
if ((imageFilesPng.Length + imageFilesJpg.Length) > 0){
126+
127+
string imageFile = null;
128+
if (imageFilesPng.Length > 0 && imageFilesJpg.Length > 0)
129+
{
130+
int total = imageFilesPng.Length + imageFilesJpg.Length;
131+
int index = _random.Next(0, total);
132+
if (index >= imageFilesPng.Length)
133+
{
134+
imageFile = imageFilesJpg[index - imageFilesPng.Length];
135+
} else
136+
{
137+
imageFile = imageFilesPng[index];
138+
}
139+
140+
} else if (imageFilesJpg.Length > 0)
141+
{
142+
imageFile = imageFilesJpg[(_random.Next(0, imageFilesJpg.Length))];
143+
}
144+
else
145+
{
146+
imageFile = imageFilesPng[(_random.Next(0, imageFilesPng.Length))];
147+
}
124148
// click the browse button
125149
targetElement = Driver.FindElement(By.XPath("//label[text()='Share what you are thinking here...']//following-sibling::input[@type='file']"));
126150
if (targetElement != null)

src/ghosts.client.linux/Handlers/SocialHelper.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,35 @@ public override bool DoPost(TimelineHandler handler, string action)
118118
Thread.Sleep(500);
119119
if (action == "postWimage"){
120120
// get the image file
121-
string[] imageFiles = Directory.GetFiles(postDirectory, "image*.png");
122-
if (imageFiles.Length > 0){
123-
string imageFile = imageFiles[(_random.Next(0, imageFiles.Length))];
121+
string[] imageFilesPng = Directory.GetFiles(postDirectory, "image*.png");
122+
string[] imageFilesJpg = Directory.GetFiles(postDirectory, "image*.jpg");
123+
124+
if ((imageFilesPng.Length + imageFilesJpg.Length) > 0)
125+
{
126+
127+
string imageFile = null;
128+
if (imageFilesPng.Length > 0 && imageFilesJpg.Length > 0)
129+
{
130+
int total = imageFilesPng.Length + imageFilesJpg.Length;
131+
int index = _random.Next(0, total);
132+
if (index >= imageFilesPng.Length)
133+
{
134+
imageFile = imageFilesJpg[index - imageFilesPng.Length];
135+
}
136+
else
137+
{
138+
imageFile = imageFilesPng[index];
139+
}
140+
141+
}
142+
else if (imageFilesJpg.Length > 0)
143+
{
144+
imageFile = imageFilesJpg[(_random.Next(0, imageFilesJpg.Length))];
145+
}
146+
else
147+
{
148+
imageFile = imageFilesPng[(_random.Next(0, imageFilesPng.Length))];
149+
}
124150
// click the browse button
125151
targetElement = Driver.FindElement(By.XPath("//label[text()='Share what you are thinking here...']//following-sibling::input[@type='file']"));
126152
if (targetElement != null)

src/ghosts.client.linux/Infrastructure/LinuxSupport.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private static void ErrorHandler(object sendingProcess, DataReceivedEventArgs ou
3939
return;
4040
}
4141

42-
private void ExecuteBashCommand(string id, string command)
42+
private string ExecuteBashCommand(string id, string command)
4343
{
4444
var escapedArgs = command.Replace("\"", "\\\"");
4545

@@ -66,17 +66,32 @@ private void ExecuteBashCommand(string id, string command)
6666

6767
p.WaitForExit();
6868
Log.Trace($"Social:: Bash command output: {Result}");
69+
return Result;
6970
}
7071

7172
public void AttachFile()
7273
{
73-
string cmd = $"xdotool search -name '{windowTitle}' windowfocus type '{filename}' ";
74-
ExecuteBashCommand(id, cmd);
75-
Thread.Sleep(500);
76-
cmd = $"xdotool search -name '{windowTitle}' windowfocus key KP_Enter";
77-
ExecuteBashCommand(id, cmd);
78-
Thread.Sleep(300);
79-
return;
74+
try {
75+
string cmd = $"xdotool search -name '{windowTitle}' windowfocus type '{filename}' ";
76+
ExecuteBashCommand(id, cmd);
77+
Thread.Sleep(2000);
78+
cmd = $"xdotool search -name '{windowTitle}' windowfocus key KP_Enter";
79+
ExecuteBashCommand(id, cmd);
80+
Thread.Sleep(2000);
81+
// Check if the window has closed
82+
cmd = $"xdotool search -name '{windowTitle}'";
83+
string result = ExecuteBashCommand(id, cmd);
84+
if (result != "") {
85+
// close the window
86+
cmd = $"xdotool search -name '{windowTitle}' windowfocus key alt+c";
87+
ExecuteBashCommand(id, cmd);
88+
Thread.Sleep(500);
89+
}
90+
return;
91+
}
92+
catch (Exception e) {
93+
Log.Error(e);
94+
}
8095
}
8196

8297

src/ghosts.tools.socialcontent/Readme.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ repo due to the size of the content, and the ability to easily generate your own
77

88
The Social browser helper expects a directory tree of static content that is used to make posts to Socializer.
99
The format of the social content directory is assumed as:
10-
`<social-content-directory>/ topicdirs(multiple) / postdirs (mulitple) / post.txt, image*.png`
10+
`<social-content-directory>/ topicdirs(multiple) / postdirs (mulitple) / post.txt, image*.png or image*.jpg`
1111

12-
When the Social Browser, various `ollama` LLMs were used to generate text, and Stable Diffusion AI was used to
12+
When the Social Browser, various `ollama` LLMs were used to generate text, and Stable Diffusion AI and Dalle3 was used to
1313
generate images.
1414

1515
You will need to install `ollama` and Python+ollama library to generate the text files.
1616
You will need to install the Stable Diffusion AI tool on your local PC in order to generate images.
17+
You will need to have an OpenAI account and ($$) to use dall-e-3 -- this gives better images than Stable AI
18+
but is more restrictive in its prompts and costs $$ for each image.
1719

1820
There was not a lot of effort expended on these scripts, they were done in one weekend so feel free to
1921
improve to your particular needs!
@@ -29,15 +31,17 @@ LLM name and post number to distinguish when different LLMs are used for the sam
2931
cleaning up posts to know what LLM was used to generate the post.
3032

3133
2. Use the `gen_social_posts.py` script to read a topic YML file - this reads each topic prompt, feed its to a LLM, captures
32-
the output, and saves the output as a post file. There are variables in `gen_soical_posts.py` script to specifiy which LLMs to
34+
the output, and saves the output as a post file. There are variables in `gen_socoal_posts.py` script to specifiy which LLMs to
3335
use to generate the post topics. The `gen_social_posts.py` script includes a function named `gen_prompts` from the
3436
`gen_topics_common.py` file to do the work of generating the post, and also attempts to clean up the post a bit after
3537
it is generated.
3638

3739

38-
## Generating Images
40+
## Generating Images/Stable AI
3941

40-
Images are optional, they are only posted if avaiable.
42+
Images are optional, they are only posted if avaiable. The default format that is generated is .PNG,
43+
but this should be converted to a JPG after the fact to save disk space (the script convert_all_images.py
44+
can be used to do this).
4145

4246
This assumes that the Stable Diffusion AI is running on the local host and can be accessed at the
4347
standard port of `127.0.0.1:7860`.
@@ -60,19 +64,43 @@ Stable AI and you can modify some of the parameters
6064
The quality of the images is not very good but should ok for traffic gen and laughs.
6165

6266

67+
## Generating Images/Dall-e-3
68+
69+
To generate images with dall-e-3 you will need an Open AI account, and put some $$ into your account in order
70+
to generate an image. You will also need to generate an API key on your account - you can use the
71+
the `dall3_test.py` script to test out your API key and image gen.
72+
73+
Once you have an API key working, you will need to add it in to `gen_topics_common.py` file in the `gen_dalle3_images`
74+
function. The script `gen_dalle3_prompts.py` can be used to generate prompts, and the `gen_dalle3_image.py` script
75+
to generate images from the prompts. Dall-e-3 generates better looking images than Stable AI but does
76+
not allow style guidance (ie, 'in the style of SoandSo') and is in general more restrictive over what can be used in a prompt.
77+
78+
6379
## Suggested Steps
6480

6581
First, just try creating 50 posts using the `gen_social_posts.py` script and `animal_content.yml` data file.
6682
Then try creating images for these posts using the `gen_stable_ai_images.py` script.
6783

6884
Once you get familar with this flow, you can change the LLM used in the `gen_social_posts.py` script and generate
69-
50 more posts about animals using a different LLM.
85+
50 more posts about animals using a different LLM.
7086

71-
Or, you can try making a content file for a different topic - currently there are four content/prompt generator files:
87+
For images, it is best to stick with one LLM for generating prompts - gemma seemed to be the best.
88+
For post content, you can use different LLMs but different LLMs end up sticking different extraneous stuff
89+
in the post that has to filtered out. Sticking with one LLM for post content makes it easier, but then the posts
90+
end up looking the same.
91+
92+
Or, you can try making a content file for a different topic - currently there are 11 content/prompt generator files:
7293
1. animal_content.yml (prompt generator is `gen_animal_topics.py`)
7394
1. movie_content.yml (prompt generator is `gen_movie_topics.py`)
7495
1. product_content.yml (prompt generator is `gen_product_topics.py`)
7596
1. travel_content.yml (prompt generator is `gen_travel_topics.py`)
97+
1. anime_content.yml (prompt generator is `gen_anime_topics.py`)
98+
1. astronomy_content.yml (prompt generator is `gen_astronomy_topics.py`)
99+
1. music_content.yml (prompt generator is `gen_music_topics.py`)
100+
1. paranormal_content.yml (prompt generator is `gen_paranormal_topics.py`)
101+
1. science_content.yml (prompt generator is `gen_science_topics.py`)
102+
1. history_content.yml (prompt generator is `gen_history_topics.py`)
103+
1. sports_content.yml (prompt generator is `gen_sports_topics.py`)
76104

77105

78106
You should be able to easily generate enough static content to satisfy traffic generator needs.
@@ -91,6 +119,10 @@ Here are links on various topics:
91119
1. Ollama Python library - https://github.com/ollama/ollama-python
92120
1. Ollama LLM Model list - https://ollama.com/library
93121
2. Stable Diffusion AI API Guide - https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API#api-guide-by-kilvoctu
122+
3. Open AI Python library: https://github.com/openai/openai-python
123+
4. Open AI playground: https://platform.openai.com/
124+
125+
94126

95127

96128

0 commit comments

Comments
 (0)