Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
a73c447
1
Parent(s): 99a6290
fix
Browse files- Dockerfile +1 -3
- pydvpl_bot.py +26 -35
Dockerfile
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
FROM python:3.12-slim
|
| 2 |
|
| 3 |
-
RUN cat /etc/resolv.conf
|
| 4 |
-
|
| 5 |
RUN useradd -m -u 1000 rifsxd
|
| 6 |
|
| 7 |
USER rifsxd
|
|
@@ -12,7 +10,7 @@ ENV HOME=/home/rifsxd \
|
|
| 12 |
|
| 13 |
WORKDIR $HOME/app
|
| 14 |
|
| 15 |
-
RUN pip install --no-cache-dir -U discord.py pydvpl fastapi uvicorn psutil python-dotenv python-tgpt craiyon.py
|
| 16 |
|
| 17 |
COPY --chown=rifsxd . $HOME/app
|
| 18 |
|
|
|
|
| 1 |
FROM python:3.12-slim
|
| 2 |
|
|
|
|
|
|
|
| 3 |
RUN useradd -m -u 1000 rifsxd
|
| 4 |
|
| 5 |
USER rifsxd
|
|
|
|
| 10 |
|
| 11 |
WORKDIR $HOME/app
|
| 12 |
|
| 13 |
+
RUN pip install --no-cache-dir -U discord.py pydvpl fastapi uvicorn psutil python-dotenv python-tgpt craiyon.py
|
| 14 |
|
| 15 |
COPY --chown=rifsxd . $HOME/app
|
| 16 |
|
pydvpl_bot.py
CHANGED
|
@@ -578,48 +578,39 @@ async def chat(ctx, model, *, message):
|
|
| 578 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 579 |
|
| 580 |
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
# Define a custom DNS resolver
|
| 588 |
-
resolver = aiohttp.resolver.AsyncResolver(nameservers=[custom_dns_server])
|
| 589 |
|
| 590 |
-
#
|
| 591 |
-
|
| 592 |
-
async with aiohttp.ClientSession() as session:
|
| 593 |
-
# Configure session with custom DNS resolver
|
| 594 |
-
session._connector = aiohttp.TCPConnector(resolver=resolver)
|
| 595 |
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
generated_images = await generator.async_generate(prompt)
|
| 600 |
|
| 601 |
-
|
| 602 |
-
|
| 603 |
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
|
| 611 |
-
|
| 612 |
-
|
| 613 |
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
|
| 619 |
-
|
| 620 |
-
@bot.hybrid_command(help="Generate images with 'craiyon' ai.")
|
| 621 |
-
async def image(ctx, *, prompt: str):
|
| 622 |
-
await image_command(ctx, prompt=prompt)
|
| 623 |
|
| 624 |
|
| 625 |
|
|
|
|
| 578 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 579 |
|
| 580 |
|
| 581 |
+
@bot.hybrid_command(help="Generate images with 'craiyon' ai.")
|
| 582 |
+
async def image(ctx, *, prompt: str):
|
| 583 |
+
# Check if the user is authorized to use the command
|
| 584 |
+
if str(ctx.author.id) not in AUTHORIZED_AI_ACCESS_ID:
|
| 585 |
+
await ctx.send("You are not authorized to use this command.")
|
| 586 |
+
return
|
|
|
|
|
|
|
| 587 |
|
| 588 |
+
# Inform the user that the generation process has started
|
| 589 |
+
await ctx.send(f"Generating images for prompt: `{prompt}`. Please be patient...")
|
|
|
|
|
|
|
|
|
|
| 590 |
|
| 591 |
+
try:
|
| 592 |
+
generator = Craiyon()
|
| 593 |
+
generated_images = await generator.async_generate(prompt)
|
|
|
|
| 594 |
|
| 595 |
+
# Encode images to base64
|
| 596 |
+
b64_list = await craiyon_utils.async_encode_base64(generated_images.images)
|
| 597 |
|
| 598 |
+
# Prepare images for sending
|
| 599 |
+
images = []
|
| 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 |
+
# Send images to the user
|
| 606 |
+
await ctx.reply(files=images)
|
| 607 |
|
| 608 |
+
except Exception as e:
|
| 609 |
+
# Print the specific exception message for debugging
|
| 610 |
+
print(f"An error occurred while generating images: {e}")
|
| 611 |
+
await ctx.send("An error occurred while generating images. Please try again later.")
|
| 612 |
|
| 613 |
+
await ctx.send(f"The command `image` was executed by - {ctx.author.mention}")
|
|
|
|
|
|
|
|
|
|
| 614 |
|
| 615 |
|
| 616 |
|