Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
137f80d
1
Parent(s): 59ad48c
update
Browse files- pydvpl_bot.py +16 -12
pydvpl_bot.py
CHANGED
|
@@ -19,6 +19,7 @@ from craiyon import Craiyon, craiyon_utils
|
|
| 19 |
from io import BytesIO
|
| 20 |
import base64
|
| 21 |
import craiyon
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
|
|
@@ -589,21 +590,24 @@ async def image(ctx, *, prompt: str):
|
|
| 589 |
await ctx.send(f"Generating images for prompt: `{prompt}`. Please be patient...")
|
| 590 |
|
| 591 |
try:
|
| 592 |
-
|
| 593 |
-
generated_images = await generator.async_generate(prompt)
|
| 594 |
|
| 595 |
-
|
| 596 |
-
|
|
|
|
| 597 |
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
for index, image_b64 in enumerate(b64_list):
|
| 601 |
-
img_bytes = BytesIO(base64.b64decode(image_b64))
|
| 602 |
-
image_file = discord.File(img_bytes, filename=f"result{index}.webp")
|
| 603 |
-
images.append(image_file)
|
| 604 |
|
| 605 |
-
|
| 606 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
|
| 608 |
except Exception as e:
|
| 609 |
# Print the specific exception message for debugging
|
|
|
|
| 19 |
from io import BytesIO
|
| 20 |
import base64
|
| 21 |
import craiyon
|
| 22 |
+
import aiohttp
|
| 23 |
|
| 24 |
|
| 25 |
|
|
|
|
| 590 |
await ctx.send(f"Generating images for prompt: `{prompt}`. Please be patient...")
|
| 591 |
|
| 592 |
try:
|
| 593 |
+
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}
|
|
|
|
| 594 |
|
| 595 |
+
async with aiohttp.ClientSession(headers=headers) as session:
|
| 596 |
+
generator = Craiyon(session=session)
|
| 597 |
+
generated_images = await generator.async_generate(prompt)
|
| 598 |
|
| 599 |
+
# Encode images to base64
|
| 600 |
+
b64_list = await craiyon_utils.async_encode_base64(generated_images.images)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 601 |
|
| 602 |
+
# Prepare images for sending
|
| 603 |
+
images = []
|
| 604 |
+
for index, image_b64 in enumerate(b64_list):
|
| 605 |
+
img_bytes = BytesIO(base64.b64decode(image_b64))
|
| 606 |
+
image_file = discord.File(img_bytes, filename=f"result{index}.webp")
|
| 607 |
+
images.append(image_file)
|
| 608 |
+
|
| 609 |
+
# Send images to the user
|
| 610 |
+
await ctx.reply(files=images)
|
| 611 |
|
| 612 |
except Exception as e:
|
| 613 |
# Print the specific exception message for debugging
|