1
1
import discord
2
2
import asyncio
3
3
import requests
4
+ import os
4
5
from PIL import Image
5
6
from io import BytesIO
6
7
from re_edge_gpt import ImageGenAsync
7
8
from src .log import setup_logger
8
9
from src .image .button_view import ButtonView
10
+ from dotenv import load_dotenv
11
+
12
+ load_dotenv ()
9
13
10
14
logger = setup_logger (__name__ )
11
15
@@ -17,13 +21,12 @@ async def create_image(interaction: discord.Interaction, users_chatbot: dict, pr
17
21
user_id = interaction .user .id
18
22
username = interaction .user
19
23
channel = interaction .channel
20
- prompts = f"> **{ prompt } ** - <@{ str (interaction . user . id )} > (***BingImageCreator***)\n \n "
24
+ prompts = f"> **{ prompt } ** - <@{ str (user_id )} > (***BingImageCreator***)\n \n "
21
25
22
- logger .info (f"\x1b [31m{ username } \x1b [0m : '{ prompt } ' ({ channel } ) [BingImageCreator]" )
26
+ logger .info (f"\x1b [31m{ username } \x1b [0m: '{ prompt } ' ({ channel } ) [BingImageCreator]" )
23
27
24
- # Fetches image links
25
28
async_gen = ImageGenAsync (auth_cookie = auth_cookie , quiet = True )
26
- images = await async_gen .get_images (prompt = prompt , timeout = 300 )
29
+ images = await async_gen .get_images (prompt = prompt , timeout = int ( os . getenv ( "IMAGE_TIMEOUT" )), max_generate_time_sec = int ( os . getenv ( "IMAGE_MAX_CREATE_SEC" )) )
27
30
images = [file for file in images if not file .endswith ('.svg' )]
28
31
new_image = await concatenate_images (images )
29
32
image_data = BytesIO ()
@@ -32,11 +35,11 @@ async def create_image(interaction: discord.Interaction, users_chatbot: dict, pr
32
35
33
36
await interaction .followup .send (prompts , file = discord .File (fp = image_data , filename = 'new_image.png' ), view = ButtonView (interaction , prompt , images , users_chatbot , user_id ))
34
37
except asyncio .TimeoutError :
35
- await interaction .followup .send ("> **Error: Request timed out.**" )
36
- logger .error ("Error while create image: Request timed out." )
38
+ await interaction .followup .send ("> **Error: Request timed out.**" )
39
+ logger .error ("Error while create image: Request timed out." )
37
40
except Exception as e :
38
- await interaction .followup .send (f"> **Error: { e } **" )
39
- logger .error (f"Error while create image: { e } " )
41
+ await interaction .followup .send (f"> **Error: { e } **" )
42
+ logger .error (f"Error while create image: { e } " )
40
43
41
44
async def concatenate_images (image_urls ):
42
45
images = [Image .open (BytesIO (requests .get (url ).content )) for url in image_urls ]
0 commit comments