seawolf2357 commited on
Commit
295a949
ยท
verified ยท
1 Parent(s): c472426

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -6,6 +6,8 @@ from transformers import pipeline
6
  import subprocess
7
  import io
8
  from PIL import Image
 
 
9
 
10
  # ๋กœ๊น… ์„ค์ •
11
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
@@ -78,6 +80,26 @@ class MyClient(discord.Client):
78
  # "!image" ๋ช…๋ น์–ด๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ์•ˆ๋‚ด ๋ฉ”์‹œ์ง€ ์ „์†ก
79
  await message.channel.send('์˜ฌ๋ฐ”๋ฅธ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. ์˜ˆ) "!image ๊ท€์—ฌ์šด ๊ณ ์–‘์ด๊ฐ€ ์ž ์„ ์ž๊ณ ์žˆ๋‹ค." ๋“ฑ์œผ๋กœ ์ž…๋ ฅํ•˜์‹œ๋ฉด ์ด๋ฏธ์ง€๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.')
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  # ๋ด‡ ์‹คํ–‰
82
  if __name__ == "__main__":
83
  discord_token = os.getenv('DISCORD_TOKEN')
 
6
  import subprocess
7
  import io
8
  from PIL import Image
9
+ import time
10
+
11
 
12
  # ๋กœ๊น… ์„ค์ •
13
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
 
80
  # "!image" ๋ช…๋ น์–ด๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ์•ˆ๋‚ด ๋ฉ”์‹œ์ง€ ์ „์†ก
81
  await message.channel.send('์˜ฌ๋ฐ”๋ฅธ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. ์˜ˆ) "!image ๊ท€์—ฌ์šด ๊ณ ์–‘์ด๊ฐ€ ์ž ์„ ์ž๊ณ ์žˆ๋‹ค." ๋“ฑ์œผ๋กœ ์ž…๋ ฅํ•˜์‹œ๋ฉด ์ด๋ฏธ์ง€๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.')
82
 
83
+
84
+ def generate_image_with_retry(prompt, negative_prompt, max_retries=3):
85
+ headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
86
+ combined_prompt = f"{prompt}. {negative_prompt}"
87
+ data = {"inputs": combined_prompt}
88
+ api_url = "https://api-inference.huggingface.co/models/fluently/Fluently-XL-Final"
89
+
90
+ for attempt in range(max_retries):
91
+ response = requests.post(api_url, headers=headers, json=data)
92
+ if response.status_code == 200:
93
+ return response.json()[0]['url']
94
+ elif response.status_code == 503 and 'estimated_time' in response.json():
95
+ wait_time = response.json()['estimated_time']
96
+ logging.info(f"๋ชจ๋ธ ๋กœ๋”ฉ ์ค‘, {wait_time}์ดˆ ํ›„ ์žฌ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค.")
97
+ time.sleep(wait_time) # ๋Œ€๊ธฐ ํ›„ ์žฌ์‹œ๋„
98
+ else:
99
+ logging.error(f"API ์š”์ฒญ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค: {response.text}")
100
+ return None
101
+ logging.error("์ตœ๋Œ€ ์žฌ์‹œ๋„ ํšŸ์ˆ˜ ์ดˆ๊ณผ")
102
+ return None
103
  # ๋ด‡ ์‹คํ–‰
104
  if __name__ == "__main__":
105
  discord_token = os.getenv('DISCORD_TOKEN')