Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -96,11 +96,23 @@ def query(payload, max_retries=5):
|
|
96 |
|
97 |
# Function for direct prompt to image generation
|
98 |
def generate_image_from_prompt(prompt):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
try:
|
100 |
-
|
101 |
-
return
|
102 |
except Exception as e:
|
103 |
-
|
|
|
|
|
|
|
|
|
104 |
|
105 |
|
106 |
# Assuming your 'process_audio' and 'generate_image_from_prompt' functions are defined elsewhere
|
|
|
96 |
|
97 |
# Function for direct prompt to image generation
|
98 |
def generate_image_from_prompt(prompt):
|
99 |
+
image_bytes = query({"inputs": prompt})
|
100 |
+
|
101 |
+
if image_bytes is None:
|
102 |
+
error_img = Image.new('RGB', (300, 300), color=(255, 0, 0))
|
103 |
+
d = ImageDraw.Draw(error_img)
|
104 |
+
d.text((10, 150), "Image Generation Failed", fill=(255, 255, 255))
|
105 |
+
return error_img
|
106 |
+
|
107 |
try:
|
108 |
+
image = Image.open(io.BytesIO(image_bytes))
|
109 |
+
return image
|
110 |
except Exception as e:
|
111 |
+
print(f"Error: {e}")
|
112 |
+
error_img = Image.new('RGB', (300, 300), color=(255, 0, 0))
|
113 |
+
d = ImageDraw.Draw(error_img)
|
114 |
+
d.text((10, 150), "Invalid Image Data", fill=(255, 255, 255))
|
115 |
+
return error_img
|
116 |
|
117 |
|
118 |
# Assuming your 'process_audio' and 'generate_image_from_prompt' functions are defined elsewhere
|