Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
3cac37d
1
Parent(s): fd30eb4
update test
Browse files- pydvpl_bot.py +23 -16
pydvpl_bot.py
CHANGED
|
@@ -15,9 +15,11 @@ import pytgpt.opengpt as opengpt
|
|
| 15 |
import pytgpt.blackboxai as blackboxai
|
| 16 |
import subprocess
|
| 17 |
import pytgpt
|
|
|
|
| 18 |
from io import BytesIO
|
| 19 |
import base64
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
# ENV_LOADER ------------------------------------------------------ START
|
|
@@ -504,7 +506,7 @@ async def version(ctx):
|
|
| 504 |
# Create an embed message to display the bot version
|
| 505 |
embed = discord.Embed(
|
| 506 |
title="Version Info",
|
| 507 |
-
description=f"The current version of libraries used.",
|
| 508 |
color=discord.Color.yellow()
|
| 509 |
)
|
| 510 |
|
|
@@ -513,6 +515,7 @@ async def version(ctx):
|
|
| 513 |
embed.add_field(name="LZ4 PY Lib Version:", value=f"``{__LZ4_VERSION__}``", inline=False)
|
| 514 |
embed.add_field(name="Discord PY Version:", value=f"``{discord.__version__}``", inline=False)
|
| 515 |
embed.add_field(name="PyTGPT Lib Version:", value=f"``{pytgpt.__version__}``", inline=False)
|
|
|
|
| 516 |
|
| 517 |
# Send the embed message
|
| 518 |
await ctx.send(embed=embed)
|
|
@@ -561,29 +564,33 @@ async def chat(ctx, model, *, message):
|
|
| 561 |
|
| 562 |
@bot.hybrid_command(help="Generate images with 'craiyon' ai.")
|
| 563 |
async def image(ctx, *, prompt: str):
|
| 564 |
-
|
| 565 |
if str(ctx.author.id) not in AUTHORIZED_AI_ACCESS_ID:
|
| 566 |
-
await ctx.send("You are not authorized to use this command.
|
| 567 |
return
|
| 568 |
|
| 569 |
-
|
| 570 |
-
|
|
|
|
| 571 |
try:
|
| 572 |
generator = Craiyon()
|
| 573 |
-
generated_images = await generator.async_generate(prompt)
|
| 574 |
-
|
|
|
|
|
|
|
| 575 |
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
|
| 583 |
-
|
|
|
|
| 584 |
|
| 585 |
except Exception as e:
|
| 586 |
-
await ctx.send(f"An error occurred while generating
|
| 587 |
|
| 588 |
|
| 589 |
# UTILITY USER_CMD ------------------------------------------------------ END
|
|
|
|
| 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 |
+
import craiyon
|
| 22 |
+
|
| 23 |
|
| 24 |
|
| 25 |
# ENV_LOADER ------------------------------------------------------ START
|
|
|
|
| 506 |
# Create an embed message to display the bot version
|
| 507 |
embed = discord.Embed(
|
| 508 |
title="Version Info",
|
| 509 |
+
description=f"The current version of libraries used in `PyDVPL`.",
|
| 510 |
color=discord.Color.yellow()
|
| 511 |
)
|
| 512 |
|
|
|
|
| 515 |
embed.add_field(name="LZ4 PY Lib Version:", value=f"``{__LZ4_VERSION__}``", inline=False)
|
| 516 |
embed.add_field(name="Discord PY Version:", value=f"``{discord.__version__}``", inline=False)
|
| 517 |
embed.add_field(name="PyTGPT Lib Version:", value=f"``{pytgpt.__version__}``", inline=False)
|
| 518 |
+
embed.add_field(name="Craiyon Lib Version:", value=f"``{craiyon.__version__}``", inline=False)
|
| 519 |
|
| 520 |
# Send the embed message
|
| 521 |
await ctx.send(embed=embed)
|
|
|
|
| 564 |
|
| 565 |
@bot.hybrid_command(help="Generate images with 'craiyon' ai.")
|
| 566 |
async def image(ctx, *, prompt: str):
|
| 567 |
+
# Check if the user is authorized to use the command
|
| 568 |
if str(ctx.author.id) not in AUTHORIZED_AI_ACCESS_ID:
|
| 569 |
+
await ctx.send("You are not authorized to use this command.")
|
| 570 |
return
|
| 571 |
|
| 572 |
+
# Inform the user that the generation process has started
|
| 573 |
+
await ctx.send(f"Generating images for prompt: `{prompt}`. Please be patient...")
|
| 574 |
+
|
| 575 |
try:
|
| 576 |
generator = Craiyon()
|
| 577 |
+
generated_images = await generator.async_generate(prompt)
|
| 578 |
+
|
| 579 |
+
# Encode images to base64
|
| 580 |
+
b64_list = await craiyon_utils.async_encode_base64(generated_images.images)
|
| 581 |
|
| 582 |
+
# Prepare images for sending
|
| 583 |
+
images = []
|
| 584 |
+
for index, image_b64 in enumerate(b64_list):
|
| 585 |
+
img_bytes = BytesIO(base64.b64decode(image_b64))
|
| 586 |
+
image_file = discord.File(img_bytes, filename=f"result{index}.webp")
|
| 587 |
+
images.append(image_file)
|
| 588 |
|
| 589 |
+
# Send images to the user
|
| 590 |
+
await ctx.reply(files=images)
|
| 591 |
|
| 592 |
except Exception as e:
|
| 593 |
+
await ctx.send(f"An error occurred while generating images: {e}")
|
| 594 |
|
| 595 |
|
| 596 |
# UTILITY USER_CMD ------------------------------------------------------ END
|