Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
•
eeb1a34
1
Parent(s):
b1244a4
Update app.py
Browse files
app.py
CHANGED
@@ -53,13 +53,16 @@ class MyClient(discord.Client):
|
|
53 |
async def generate_image(prompt):
|
54 |
try:
|
55 |
# 모델 호출
|
56 |
-
response = hf_client(inputs=prompt)
|
57 |
-
image_data = response
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
63 |
except Exception as e:
|
64 |
logging.error(f"Failed to generate image: {str(e)}")
|
65 |
return None
|
|
|
53 |
async def generate_image(prompt):
|
54 |
try:
|
55 |
# 모델 호출
|
56 |
+
response = hf_client(inputs={"inputs": prompt}, options={"wait_for_model": True}) # options는 필요에 따라 조정 가능
|
57 |
+
image_data = response.get('images', [None])[0] # 응답에서 이미지 데이터 추출
|
58 |
+
if image_data:
|
59 |
+
image_bytes = io.BytesIO(base64.b64decode(image_data))
|
60 |
+
image = Image.open(image_bytes)
|
61 |
+
image_path = "output.png"
|
62 |
+
image.save(image_path)
|
63 |
+
return image_path
|
64 |
+
else:
|
65 |
+
raise ValueError("No image data received.")
|
66 |
except Exception as e:
|
67 |
logging.error(f"Failed to generate image: {str(e)}")
|
68 |
return None
|