Skip to content

Commit

Permalink
Merge pull request #362 from rbreesems/update_june2024
Browse files Browse the repository at this point in the history
Update june2024
  • Loading branch information
sei-dupdyke authored Jun 6, 2024
2 parents f0457b2 + 6fd5a60 commit e14fec3
Show file tree
Hide file tree
Showing 27 changed files with 2,010 additions and 40 deletions.
30 changes: 27 additions & 3 deletions src/Ghosts.Client/Handlers/SocialHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Linq;
using System.Collections.Generic;
using Ghosts.Client.Infrastructure;
using System.Web.UI.WebControls;



Expand Down Expand Up @@ -118,9 +119,32 @@ public override bool DoPost(TimelineHandler handler, string action)
Thread.Sleep(500);
if (action == "postWimage"){
// get the image file
string[] imageFiles = Directory.GetFiles(postDirectory, "image*.png");
if (imageFiles.Length > 0){
string imageFile = imageFiles[(_random.Next(0, imageFiles.Length))];
string[] imageFilesPng = Directory.GetFiles(postDirectory, "image*.png");
string[] imageFilesJpg = Directory.GetFiles(postDirectory, "image*.jpg");

if ((imageFilesPng.Length + imageFilesJpg.Length) > 0){

string imageFile = null;
if (imageFilesPng.Length > 0 && imageFilesJpg.Length > 0)
{
int total = imageFilesPng.Length + imageFilesJpg.Length;
int index = _random.Next(0, total);
if (index >= imageFilesPng.Length)
{
imageFile = imageFilesJpg[index - imageFilesPng.Length];
} else
{
imageFile = imageFilesPng[index];
}

} else if (imageFilesJpg.Length > 0)
{
imageFile = imageFilesJpg[(_random.Next(0, imageFilesJpg.Length))];
}
else
{
imageFile = imageFilesPng[(_random.Next(0, imageFilesPng.Length))];
}
// click the browse button
targetElement = Driver.FindElement(By.XPath("//label[text()='Share what you are thinking here...']//following-sibling::input[@type='file']"));
if (targetElement != null)
Expand Down
32 changes: 29 additions & 3 deletions src/ghosts.client.linux/Handlers/SocialHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,35 @@ public override bool DoPost(TimelineHandler handler, string action)
Thread.Sleep(500);
if (action == "postWimage"){
// get the image file
string[] imageFiles = Directory.GetFiles(postDirectory, "image*.png");
if (imageFiles.Length > 0){
string imageFile = imageFiles[(_random.Next(0, imageFiles.Length))];
string[] imageFilesPng = Directory.GetFiles(postDirectory, "image*.png");
string[] imageFilesJpg = Directory.GetFiles(postDirectory, "image*.jpg");

if ((imageFilesPng.Length + imageFilesJpg.Length) > 0)
{

string imageFile = null;
if (imageFilesPng.Length > 0 && imageFilesJpg.Length > 0)
{
int total = imageFilesPng.Length + imageFilesJpg.Length;
int index = _random.Next(0, total);
if (index >= imageFilesPng.Length)
{
imageFile = imageFilesJpg[index - imageFilesPng.Length];
}
else
{
imageFile = imageFilesPng[index];
}

}
else if (imageFilesJpg.Length > 0)
{
imageFile = imageFilesJpg[(_random.Next(0, imageFilesJpg.Length))];
}
else
{
imageFile = imageFilesPng[(_random.Next(0, imageFilesPng.Length))];
}
// click the browse button
targetElement = Driver.FindElement(By.XPath("//label[text()='Share what you are thinking here...']//following-sibling::input[@type='file']"));
if (targetElement != null)
Expand Down
31 changes: 23 additions & 8 deletions src/ghosts.client.linux/Infrastructure/LinuxSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static void ErrorHandler(object sendingProcess, DataReceivedEventArgs ou
return;
}

private void ExecuteBashCommand(string id, string command)
private string ExecuteBashCommand(string id, string command)
{
var escapedArgs = command.Replace("\"", "\\\"");

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

p.WaitForExit();
Log.Trace($"Social:: Bash command output: {Result}");
return Result;
}

public void AttachFile()
{
string cmd = $"xdotool search -name '{windowTitle}' windowfocus type '{filename}' ";
ExecuteBashCommand(id, cmd);
Thread.Sleep(500);
cmd = $"xdotool search -name '{windowTitle}' windowfocus key KP_Enter";
ExecuteBashCommand(id, cmd);
Thread.Sleep(300);
return;
try {
string cmd = $"xdotool search -name '{windowTitle}' windowfocus type '{filename}' ";
ExecuteBashCommand(id, cmd);
Thread.Sleep(2000);
cmd = $"xdotool search -name '{windowTitle}' windowfocus key KP_Enter";
ExecuteBashCommand(id, cmd);
Thread.Sleep(2000);
// Check if the window has closed
cmd = $"xdotool search -name '{windowTitle}'";
string result = ExecuteBashCommand(id, cmd);
if (result != "") {
// close the window
cmd = $"xdotool search -name '{windowTitle}' windowfocus key alt+c";
ExecuteBashCommand(id, cmd);
Thread.Sleep(500);
}
return;
}
catch (Exception e) {
Log.Error(e);
}
}


Expand Down
46 changes: 39 additions & 7 deletions src/ghosts.tools.socialcontent/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ repo due to the size of the content, and the ability to easily generate your own

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

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

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

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

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
the output, and saves the output as a post file. There are variables in `gen_soical_posts.py` script to specifiy which LLMs to
the output, and saves the output as a post file. There are variables in `gen_socoal_posts.py` script to specifiy which LLMs to
use to generate the post topics. The `gen_social_posts.py` script includes a function named `gen_prompts` from the
`gen_topics_common.py` file to do the work of generating the post, and also attempts to clean up the post a bit after
it is generated.


## Generating Images
## Generating Images/Stable AI

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

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


## Generating Images/Dall-e-3

To generate images with dall-e-3 you will need an Open AI account, and put some $$ into your account in order
to generate an image. You will also need to generate an API key on your account - you can use the
the `dall3_test.py` script to test out your API key and image gen.

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`
function. The script `gen_dalle3_prompts.py` can be used to generate prompts, and the `gen_dalle3_image.py` script
to generate images from the prompts. Dall-e-3 generates better looking images than Stable AI but does
not allow style guidance (ie, 'in the style of SoandSo') and is in general more restrictive over what can be used in a prompt.


## Suggested Steps

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

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

Or, you can try making a content file for a different topic - currently there are four content/prompt generator files:
For images, it is best to stick with one LLM for generating prompts - gemma seemed to be the best.
For post content, you can use different LLMs but different LLMs end up sticking different extraneous stuff
in the post that has to filtered out. Sticking with one LLM for post content makes it easier, but then the posts
end up looking the same.

Or, you can try making a content file for a different topic - currently there are 11 content/prompt generator files:
1. animal_content.yml (prompt generator is `gen_animal_topics.py`)
1. movie_content.yml (prompt generator is `gen_movie_topics.py`)
1. product_content.yml (prompt generator is `gen_product_topics.py`)
1. travel_content.yml (prompt generator is `gen_travel_topics.py`)
1. anime_content.yml (prompt generator is `gen_anime_topics.py`)
1. astronomy_content.yml (prompt generator is `gen_astronomy_topics.py`)
1. music_content.yml (prompt generator is `gen_music_topics.py`)
1. paranormal_content.yml (prompt generator is `gen_paranormal_topics.py`)
1. science_content.yml (prompt generator is `gen_science_topics.py`)
1. history_content.yml (prompt generator is `gen_history_topics.py`)
1. sports_content.yml (prompt generator is `gen_sports_topics.py`)


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





Expand Down
Loading

0 comments on commit e14fec3

Please sign in to comment.