Sriv890 commited on
Commit
36c08ed
·
verified ·
1 Parent(s): 325b08e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
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
- image_bytes = query({"inputs": prompt})
101
- return image_bytes
102
  except Exception as e:
103
- return f"An error occurred during image generation: {str(e)}"
 
 
 
 
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