diff --git a/.gitignore b/.gitignore index 4977b18..5144fa6 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ var/ wheels/ share/python-wheels/ *.egg-info/ +images/ .installed.cfg *.egg MANIFEST diff --git a/README.md b/README.md index 211b959..04fb431 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,34 @@ Once running, you should see a message in the console indicating that the bot ha - `!uptime`: Get bot's uptime. - `!restart`: Restart the bot (owner only). -## Conclusion -You now have a Discord bot capable of generating images using DALL-E. Enjoy and be creative with your prompts! \ No newline at end of file +# Note +- 1 only generation at a time +- cookie expires +- will output the most 4 recent images in time + + +# Todo +- make a playwright verison +- Make censorship detection if it waits, Should code some censorship detection to send a message that it couldn’t generated +- Also suggested trying playwright with a manual login instead of this cookie thing if OpenAI somehow patched it +- but yeah. there's no error. it's a bug with get_urls() where it freezes on that function +d +- No error, just when I do .run() I get this "INFO:root:[20/10/2023 21:26:56] Bing Image Creator (Dalle-3) Opened +INFO:root:[20/10/2023 21:26:58] Cookie values added " and then nothing else +- where is the log saved? +- Idk wym by paste error log cause there’s no error it just gets stuck on get_urls() +- feedback, censorship detection, +oh it suddenly started working for me +maybe it's because I didn't have undetected_chromedriver installed +but I installed it to try the other github? +- parse token usage and print and notify user if there are none left +- and if it's censored does it at least throw an error wait error around 10 seconds, it would be, perhaps we could do time timeout where it just stops everything, I think better would be to also have a loop that checks for the words "unsafe content detected" or whatever the message is +- @Kye does it tell you when the cookie expires? +- Can't we add something like before generation add you own link or something to generate? +- Make the retreival better, parse only the 4 images for the request +- parse when cookie expires somehow, set a day maybe +- that makes the need for it to say censored instead of getting stuck in a loop more prevalent +so you can properly schedule it +otherwise if it gets stuck in a loop there's no way to tell the difference programmatically if another request is still generating or it got censored +!generate photorealistic 3D render of batman made out of legos \ No newline at end of file diff --git a/app.py b/app.py index d9a9cc5..d28de89 100644 --- a/app.py +++ b/app.py @@ -16,15 +16,16 @@ #AWS # AWS S3 Configuration -AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID") -AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY") -S3_BUCKET_NAME = os.getenv("S3_BUCKET_NAME") -s3 = boto3.client('s3', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY) +# AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID") +# AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY") +# S3_BUCKET_NAME = os.getenv("S3_BUCKET_NAME") +# s3 = boto3.client('s3', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY) # keys -DISCORD_TOKEN = os.getenv("DISCORD_API_KEY") -DALLE_TOKEN = os.getenv("BING_COOKIE") +DISCORD_TOKEN = "" +DALLE_TOKEN = "" + SAVE_DIRECTORY = "images/" @@ -56,13 +57,50 @@ async def generate(ctx, *, prompt: str): # Offload the image generation to another thread await loop.run_in_executor(executor, dalle_instance.run, prompt) - - for root, dirs, files in os.walk(SAVE_DIRECTORY): - for filename in files: - filepath = os.path.join(root, filename) - await ctx.send(file=discord.File(filepath)) - - + print("Done generating images!") + + # List all files in the SAVE_DIRECTORY + all_files = [os.path.join(root, file) for root, _, files in os.walk(SAVE_DIRECTORY) for file in files] + + # Sort files by their creation time (latest first) + sorted_files = sorted(all_files, key=os.path.getctime, reverse=True) + + # Get the 4 most recent files + latest_files = sorted_files[:4] + print(f"Sending {len(latest_files)} images to Discord...") + + for filepath in latest_files: + await ctx.send(file=discord.File(filepath)) + + +# @bot.command() +# async def generate(ctx, *, prompt: str): +# """Generates images based on the provided prompt""" +# await ctx.send(f"Generating images for prompt: `{prompt}`...") + +# # Make a unique directory for this generation session using the message ID +# session_save_directory = os.path.join(SAVE_DIRECTORY, str(ctx.message.id)) +# os.makedirs(session_save_directory, exist_ok=True) + +# # Offload the image generation to another thread. +# loop = asyncio.get_event_loop() +# await loop.run_in_executor(executor, dalle_instance.run, prompt, session_save_directory) + +# # Get all the images saved in the session's directory. +# generated_images = sorted(glob.glob(os.path.join(session_save_directory, '*')), key=os.path.getctime) + +# # Upload to S3 and send the URL to the user: +# for image_path in generated_images: +# file_name = os.path.basename(image_path) +# s3.upload_file(image_path, S3_BUCKET_NAME, file_name, ExtraArgs={'ACL': 'public-read'}) + +# image_url = f"https://{S3_BUCKET_NAME}.s3.amazonaws.com/{file_name}" +# await ctx.send(image_url) + +# # Cleanup: Optionally, delete the session's directory after sending the images. +# for image_path in generated_images: +# os.remove(image_path) +# os.rmdir(session_save_directory) @bot.command() async def helpme(ctx): diff --git a/images/20-10-2023 19-46-25/image_1.png b/images/20-10-2023 19-46-25/image_1.png deleted file mode 100644 index ae75217..0000000 Binary files a/images/20-10-2023 19-46-25/image_1.png and /dev/null differ diff --git a/images/20-10-2023 19-46-25/image_2.png b/images/20-10-2023 19-46-25/image_2.png deleted file mode 100644 index 35d884e..0000000 Binary files a/images/20-10-2023 19-46-25/image_2.png and /dev/null differ diff --git a/images/20-10-2023 19-46-25/image_3.png b/images/20-10-2023 19-46-25/image_3.png deleted file mode 100644 index f9aef9b..0000000 Binary files a/images/20-10-2023 19-46-25/image_3.png and /dev/null differ diff --git a/images/20-10-2023 19-46-25/image_4.png b/images/20-10-2023 19-46-25/image_4.png deleted file mode 100644 index bbd4ef3..0000000 Binary files a/images/20-10-2023 19-46-25/image_4.png and /dev/null differ diff --git a/images/20-10-2023 19-48-36/image_1.png b/images/20-10-2023 19-48-36/image_1.png deleted file mode 100644 index 5f74198..0000000 Binary files a/images/20-10-2023 19-48-36/image_1.png and /dev/null differ diff --git a/images/20-10-2023 19-48-36/image_2.png b/images/20-10-2023 19-48-36/image_2.png deleted file mode 100644 index d8c1573..0000000 Binary files a/images/20-10-2023 19-48-36/image_2.png and /dev/null differ diff --git a/images/20-10-2023 19-48-36/image_3.png b/images/20-10-2023 19-48-36/image_3.png deleted file mode 100644 index 65a192c..0000000 Binary files a/images/20-10-2023 19-48-36/image_3.png and /dev/null differ diff --git a/images/20-10-2023 19-48-36/image_4.png b/images/20-10-2023 19-48-36/image_4.png deleted file mode 100644 index 96489c1..0000000 Binary files a/images/20-10-2023 19-48-36/image_4.png and /dev/null differ diff --git a/images/20-10-2023 19-49-12/image_1.png b/images/20-10-2023 19-49-12/image_1.png deleted file mode 100644 index faf37c2..0000000 Binary files a/images/20-10-2023 19-49-12/image_1.png and /dev/null differ diff --git a/images/20-10-2023 19-49-12/image_2.png b/images/20-10-2023 19-49-12/image_2.png deleted file mode 100644 index 0ad2867..0000000 Binary files a/images/20-10-2023 19-49-12/image_2.png and /dev/null differ diff --git a/images/20-10-2023 19-49-12/image_3.png b/images/20-10-2023 19-49-12/image_3.png deleted file mode 100644 index 8fba8bb..0000000 Binary files a/images/20-10-2023 19-49-12/image_3.png and /dev/null differ diff --git a/images/20-10-2023 19-51-12/image_1.png b/images/20-10-2023 19-51-12/image_1.png deleted file mode 100644 index f99a357..0000000 Binary files a/images/20-10-2023 19-51-12/image_1.png and /dev/null differ diff --git a/images/20-10-2023 19-51-12/image_2.png b/images/20-10-2023 19-51-12/image_2.png deleted file mode 100644 index 41dd5d7..0000000 Binary files a/images/20-10-2023 19-51-12/image_2.png and /dev/null differ diff --git a/images/20-10-2023 19-51-12/image_3.png b/images/20-10-2023 19-51-12/image_3.png deleted file mode 100644 index a5c88d5..0000000 Binary files a/images/20-10-2023 19-51-12/image_3.png and /dev/null differ diff --git a/images/20-10-2023 19-51-12/image_4.png b/images/20-10-2023 19-51-12/image_4.png deleted file mode 100644 index 5a722df..0000000 Binary files a/images/20-10-2023 19-51-12/image_4.png and /dev/null differ diff --git a/images/20-10-2023 19-56-28/image_1.png b/images/20-10-2023 19-56-28/image_1.png deleted file mode 100644 index 352d9d8..0000000 Binary files a/images/20-10-2023 19-56-28/image_1.png and /dev/null differ diff --git a/images/20-10-2023 19-56-28/image_2.png b/images/20-10-2023 19-56-28/image_2.png deleted file mode 100644 index 0016631..0000000 Binary files a/images/20-10-2023 19-56-28/image_2.png and /dev/null differ diff --git a/images/20-10-2023 19-56-28/image_3.png b/images/20-10-2023 19-56-28/image_3.png deleted file mode 100644 index 1fd754b..0000000 Binary files a/images/20-10-2023 19-56-28/image_3.png and /dev/null differ diff --git a/images/20-10-2023 19-56-28/image_4.png b/images/20-10-2023 19-56-28/image_4.png deleted file mode 100644 index 53d98c7..0000000 Binary files a/images/20-10-2023 19-56-28/image_4.png and /dev/null differ diff --git a/images/20-10-2023 19-59-21/image_1.png b/images/20-10-2023 19-59-21/image_1.png deleted file mode 100644 index 48da854..0000000 Binary files a/images/20-10-2023 19-59-21/image_1.png and /dev/null differ diff --git a/images/20-10-2023 19-59-21/image_2.png b/images/20-10-2023 19-59-21/image_2.png deleted file mode 100644 index fad0d48..0000000 Binary files a/images/20-10-2023 19-59-21/image_2.png and /dev/null differ diff --git a/images/20-10-2023 19-59-21/image_3.png b/images/20-10-2023 19-59-21/image_3.png deleted file mode 100644 index a948eba..0000000 Binary files a/images/20-10-2023 19-59-21/image_3.png and /dev/null differ diff --git a/images/20-10-2023 19-59-21/image_4.png b/images/20-10-2023 19-59-21/image_4.png deleted file mode 100644 index b58f170..0000000 Binary files a/images/20-10-2023 19-59-21/image_4.png and /dev/null differ diff --git a/images/20-10-2023 20-00-21/image_1.png b/images/20-10-2023 20-00-21/image_1.png deleted file mode 100644 index d535828..0000000 Binary files a/images/20-10-2023 20-00-21/image_1.png and /dev/null differ diff --git a/images/20-10-2023 20-00-21/image_2.png b/images/20-10-2023 20-00-21/image_2.png deleted file mode 100644 index fc67ebe..0000000 Binary files a/images/20-10-2023 20-00-21/image_2.png and /dev/null differ diff --git a/images/20-10-2023 20-00-21/image_3.png b/images/20-10-2023 20-00-21/image_3.png deleted file mode 100644 index 2ae7e48..0000000 Binary files a/images/20-10-2023 20-00-21/image_3.png and /dev/null differ diff --git a/images/20-10-2023 20-00-21/image_4.png b/images/20-10-2023 20-00-21/image_4.png deleted file mode 100644 index 0a06a34..0000000 Binary files a/images/20-10-2023 20-00-21/image_4.png and /dev/null differ diff --git a/images/20-10-2023 20-05-17/image_1.png b/images/20-10-2023 20-05-17/image_1.png deleted file mode 100644 index 0eb09e4..0000000 Binary files a/images/20-10-2023 20-05-17/image_1.png and /dev/null differ diff --git a/images/20-10-2023 20-05-17/image_2.png b/images/20-10-2023 20-05-17/image_2.png deleted file mode 100644 index 1d8c0b8..0000000 Binary files a/images/20-10-2023 20-05-17/image_2.png and /dev/null differ diff --git a/images/20-10-2023 20-05-17/image_3.png b/images/20-10-2023 20-05-17/image_3.png deleted file mode 100644 index f913b50..0000000 Binary files a/images/20-10-2023 20-05-17/image_3.png and /dev/null differ diff --git a/images/20-10-2023 20-05-17/image_4.png b/images/20-10-2023 20-05-17/image_4.png deleted file mode 100644 index 3817314..0000000 Binary files a/images/20-10-2023 20-05-17/image_4.png and /dev/null differ diff --git a/images/20-10-2023 20-07-04/image_1.png b/images/20-10-2023 20-07-04/image_1.png deleted file mode 100644 index bba4493..0000000 Binary files a/images/20-10-2023 20-07-04/image_1.png and /dev/null differ diff --git a/images/20-10-2023 20-07-04/image_2.png b/images/20-10-2023 20-07-04/image_2.png deleted file mode 100644 index bce89a9..0000000 Binary files a/images/20-10-2023 20-07-04/image_2.png and /dev/null differ diff --git a/images/20-10-2023 20-07-04/image_3.png b/images/20-10-2023 20-07-04/image_3.png deleted file mode 100644 index 4df6f53..0000000 Binary files a/images/20-10-2023 20-07-04/image_3.png and /dev/null differ diff --git a/images/20-10-2023 20-07-04/image_4.png b/images/20-10-2023 20-07-04/image_4.png deleted file mode 100644 index 4e1575a..0000000 Binary files a/images/20-10-2023 20-07-04/image_4.png and /dev/null differ