Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Oct 21, 2023
1 parent a38df16 commit cf0051e
Show file tree
Hide file tree
Showing 38 changed files with 82 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var/
wheels/
share/python-wheels/
*.egg-info/
images/
.installed.cfg
*.egg
MANIFEST
Expand Down
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
# 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
64 changes: 51 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down Expand Up @@ -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):
Expand Down
Binary file removed images/20-10-2023 19-46-25/image_1.png
Binary file not shown.
Binary file removed images/20-10-2023 19-46-25/image_2.png
Binary file not shown.
Binary file removed images/20-10-2023 19-46-25/image_3.png
Binary file not shown.
Binary file removed images/20-10-2023 19-46-25/image_4.png
Binary file not shown.
Binary file removed images/20-10-2023 19-48-36/image_1.png
Binary file not shown.
Binary file removed images/20-10-2023 19-48-36/image_2.png
Binary file not shown.
Binary file removed images/20-10-2023 19-48-36/image_3.png
Binary file not shown.
Binary file removed images/20-10-2023 19-48-36/image_4.png
Binary file not shown.
Binary file removed images/20-10-2023 19-49-12/image_1.png
Binary file not shown.
Binary file removed images/20-10-2023 19-49-12/image_2.png
Binary file not shown.
Binary file removed images/20-10-2023 19-49-12/image_3.png
Binary file not shown.
Binary file removed images/20-10-2023 19-51-12/image_1.png
Binary file not shown.
Binary file removed images/20-10-2023 19-51-12/image_2.png
Binary file not shown.
Binary file removed images/20-10-2023 19-51-12/image_3.png
Binary file not shown.
Binary file removed images/20-10-2023 19-51-12/image_4.png
Binary file not shown.
Binary file removed images/20-10-2023 19-56-28/image_1.png
Binary file not shown.
Binary file removed images/20-10-2023 19-56-28/image_2.png
Binary file not shown.
Binary file removed images/20-10-2023 19-56-28/image_3.png
Binary file not shown.
Binary file removed images/20-10-2023 19-56-28/image_4.png
Binary file not shown.
Binary file removed images/20-10-2023 19-59-21/image_1.png
Binary file not shown.
Binary file removed images/20-10-2023 19-59-21/image_2.png
Binary file not shown.
Binary file removed images/20-10-2023 19-59-21/image_3.png
Binary file not shown.
Binary file removed images/20-10-2023 19-59-21/image_4.png
Binary file not shown.
Binary file removed images/20-10-2023 20-00-21/image_1.png
Binary file not shown.
Binary file removed images/20-10-2023 20-00-21/image_2.png
Binary file not shown.
Binary file removed images/20-10-2023 20-00-21/image_3.png
Diff not rendered.
Binary file removed images/20-10-2023 20-00-21/image_4.png
Diff not rendered.
Binary file removed images/20-10-2023 20-05-17/image_1.png
Diff not rendered.
Binary file removed images/20-10-2023 20-05-17/image_2.png
Diff not rendered.
Binary file removed images/20-10-2023 20-05-17/image_3.png
Diff not rendered.
Binary file removed images/20-10-2023 20-05-17/image_4.png
Diff not rendered.
Binary file removed images/20-10-2023 20-07-04/image_1.png
Diff not rendered.
Binary file removed images/20-10-2023 20-07-04/image_2.png
Diff not rendered.
Binary file removed images/20-10-2023 20-07-04/image_3.png
Diff not rendered.
Binary file removed images/20-10-2023 20-07-04/image_4.png
Diff not rendered.

0 comments on commit cf0051e

Please sign in to comment.