Rifat Azad commited on
Commit
a73c447
·
1 Parent(s): 99a6290
Files changed (2) hide show
  1. Dockerfile +1 -3
  2. 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 aiodns
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
- import aiohttp
582
- import asyncio
583
-
584
- # Define your custom DNS server
585
- custom_dns_server = '8.8.8.8'
586
-
587
- # Define a custom DNS resolver
588
- resolver = aiohttp.resolver.AsyncResolver(nameservers=[custom_dns_server])
589
 
590
- # Function to execute the image command
591
- async def image_command(ctx, *, prompt: str):
592
- async with aiohttp.ClientSession() as session:
593
- # Configure session with custom DNS resolver
594
- session._connector = aiohttp.TCPConnector(resolver=resolver)
595
 
596
- # Your image generation logic here
597
- try:
598
- generator = Craiyon()
599
- generated_images = await generator.async_generate(prompt)
600
 
601
- # Encode images to base64
602
- b64_list = await craiyon_utils.async_encode_base64(generated_images.images)
603
 
604
- # Prepare images for sending
605
- images = []
606
- for index, image_b64 in enumerate(b64_list):
607
- img_bytes = BytesIO(base64.b64decode(image_b64))
608
- image_file = discord.File(img_bytes, filename=f"result{index}.webp")
609
- images.append(image_file)
610
 
611
- # Send images to the user
612
- await ctx.reply(files=images)
613
 
614
- except Exception as e:
615
- # Handle errors
616
- print(f"An error occurred while generating images: {e}")
617
- await ctx.send("An error occurred while generating images. Please try again later.")
618
 
619
- # Usage of the command
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