Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
fd30eb4
1
Parent(s): b975879
update test
Browse files- pydvpl_bot.py +14 -13
pydvpl_bot.py
CHANGED
|
@@ -15,10 +15,9 @@ import pytgpt.opengpt as opengpt
|
|
| 15 |
import pytgpt.blackboxai as blackboxai
|
| 16 |
import subprocess
|
| 17 |
import pytgpt
|
| 18 |
-
from craiyon import Craiyon, craiyon_utils
|
| 19 |
from io import BytesIO
|
| 20 |
import base64
|
| 21 |
-
|
| 22 |
|
| 23 |
|
| 24 |
# ENV_LOADER ------------------------------------------------------ START
|
|
@@ -569,20 +568,22 @@ async def image(ctx, *, prompt: str):
|
|
| 569 |
|
| 570 |
await ctx.send(f"Generating prompt `{prompt}` please be patient...")
|
| 571 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
img_bytes = BytesIO(base64.b64decode(image)) # Decode the image and store it as a bytes object
|
| 580 |
-
image = discord.File(img_bytes)
|
| 581 |
-
image.filename = f"result{index}.webp"
|
| 582 |
-
images1.append(image) # Add the image to the images1 list
|
| 583 |
|
| 584 |
-
|
| 585 |
|
|
|
|
|
|
|
| 586 |
|
| 587 |
|
| 588 |
# UTILITY USER_CMD ------------------------------------------------------ END
|
|
|
|
| 15 |
import pytgpt.blackboxai as blackboxai
|
| 16 |
import subprocess
|
| 17 |
import pytgpt
|
|
|
|
| 18 |
from io import BytesIO
|
| 19 |
import base64
|
| 20 |
+
from craiyon import Craiyon, craiyon_utils
|
| 21 |
|
| 22 |
|
| 23 |
# ENV_LOADER ------------------------------------------------------ START
|
|
|
|
| 568 |
|
| 569 |
await ctx.send(f"Generating prompt `{prompt}` please be patient...")
|
| 570 |
|
| 571 |
+
try:
|
| 572 |
+
generator = Craiyon()
|
| 573 |
+
generated_images = await generator.async_generate(prompt) # Generate images
|
| 574 |
+
b64_list = await craiyon_utils.async_encode_base64(generated_images.images) # Download images from https://img.craiyon.com and store them as b64 bytestring object
|
| 575 |
|
| 576 |
+
images1 = []
|
| 577 |
+
for index, image in enumerate(b64_list): # Loop through b64_list, keeping track of the index
|
| 578 |
+
img_bytes = BytesIO(base64.b64decode(image)) # Decode the image and store it as a bytes object
|
| 579 |
+
image = discord.File(img_bytes)
|
| 580 |
+
image.filename = f"result{index}.webp"
|
| 581 |
+
images1.append(image) # Add the image to the images1 list
|
|
|
|
|
|
|
|
|
|
|
|
|
| 582 |
|
| 583 |
+
await ctx.reply(files=images1) # Reply to the user with all 9 images in 1 message
|
| 584 |
|
| 585 |
+
except Exception as e:
|
| 586 |
+
await ctx.send(f"An error occurred while generating prompt `{prompt}`: {e}")
|
| 587 |
|
| 588 |
|
| 589 |
# UTILITY USER_CMD ------------------------------------------------------ END
|