Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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')
|