Rifat Azad commited on
Commit
fc8a2ef
·
1 Parent(s): 5da5089

update 1.3.1 added /image command to generate ai images

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. pydvpl_bot.py +35 -1
Dockerfile CHANGED
@@ -2,7 +2,7 @@ FROM python:3.12-slim
2
 
3
  WORKDIR /code
4
 
5
- RUN pip install --no-cache-dir -U discord pydvpl fastapi uvicorn psutil python-dotenv python-tgpt
6
 
7
  COPY ./pydvpl_bot.py /code
8
 
 
2
 
3
  WORKDIR /code
4
 
5
+ RUN pip install --no-cache-dir -U discord.py pydvpl fastapi uvicorn psutil python-dotenv python-tgpt craiyon.py
6
 
7
  COPY ./pydvpl_bot.py /code
8
 
pydvpl_bot.py CHANGED
@@ -15,6 +15,10 @@ import pytgpt.opengpt as opengpt
15
  import pytgpt.blackboxai as blackboxai
16
  import subprocess
17
  import pytgpt
 
 
 
 
18
 
19
 
20
  # ENV_LOADER ------------------------------------------------------ START
@@ -29,7 +33,7 @@ load_dotenv()
29
  # DEFINES ------------------------------------------------------ START
30
 
31
 
32
- BOT_VERSION = '1.3.0'
33
 
34
  AUTHORIZED_USER_ID = os.getenv('AUTHORIZED_ID')
35
 
@@ -553,6 +557,36 @@ async def chat(ctx, model, *, message):
553
  await ctx.send(response)
554
 
555
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
556
  # UTILITY USER_CMD ------------------------------------------------------ END
557
 
558
 
 
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
 
33
  # DEFINES ------------------------------------------------------ START
34
 
35
 
36
+ BOT_VERSION = '1.3.1'
37
 
38
  AUTHORIZED_USER_ID = os.getenv('AUTHORIZED_ID')
39
 
 
557
  await ctx.send(response)
558
 
559
 
560
+ # FUNCTION ------------------------------------------------------ SPLIT
561
+
562
+
563
+ @bot.hybrid_command(help="Generate images with 'craiyon' ai.")
564
+ async def image(ctx, *, prompt: str):
565
+
566
+ if str(ctx.author.id) not in AUTHORIZED_AI_ACCESS_ID:
567
+ await ctx.send("You are not authorized to use this command. Only `@rifsxd`'s server boosters & special permitted users can enjoy free `ChatGPT` access.")
568
+ return
569
+
570
+ await ctx.send(f"Generating prompt `{prompt}` please be patient...")
571
+
572
+ try:
573
+ generator = Craiyon()
574
+ generated_images = await generator.async_generate(prompt) # Generate images
575
+ 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
576
+
577
+ images1 = []
578
+ for index, image in enumerate(b64_list): # Loop through b64_list, keeping track of the index
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
+ await ctx.reply(files=images1) # Reply to the user with all 9 images in 1 message
585
+
586
+ except Exception as e:
587
+ await ctx.send(f"An error occurred while generating prompt `{prompt}`: {e}")
588
+
589
+
590
  # UTILITY USER_CMD ------------------------------------------------------ END
591
 
592