Update app.py
Browse files
app.py
CHANGED
@@ -70,27 +70,27 @@ def gen_fn(model_str, prompt, negative_prompt):
|
|
70 |
# except Exception as e:
|
71 |
# print(f"Error occurred: {e}")
|
72 |
# return None
|
73 |
-
|
74 |
# Attempt to generate the image
|
75 |
-
|
76 |
|
77 |
# Check if the image_response is a tuple, handle accordingly
|
78 |
-
|
79 |
# If the response is a tuple, return the first item assuming it's the image
|
80 |
-
|
81 |
|
82 |
# Ensure the response is an image or image-like object
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
|
95 |
|
96 |
|
|
|
70 |
# except Exception as e:
|
71 |
# print(f"Error occurred: {e}")
|
72 |
# return None
|
73 |
+
try:
|
74 |
# Attempt to generate the image
|
75 |
+
image_response = models_load[model_str](f'{prompt} {negative_prompt} {noise}')
|
76 |
|
77 |
# Check if the image_response is a tuple, handle accordingly
|
78 |
+
if isinstance(image_response, tuple):
|
79 |
# If the response is a tuple, return the first item assuming it's the image
|
80 |
+
image_response = image_response[0]
|
81 |
|
82 |
# Ensure the response is an image or image-like object
|
83 |
+
if isinstance(image_response, gr.Image):
|
84 |
+
return image_response
|
85 |
+
elif isinstance(image_response, str): # If the response is a path or URL, pass it as a string
|
86 |
+
return gr.Image(image_response) # You can handle it based on your model's return type
|
87 |
+
else:
|
88 |
+
print(f"Unexpected response type: {type(image_response)}")
|
89 |
+
return None
|
90 |
|
91 |
+
except Exception as e:
|
92 |
+
print(f"Error occurred: {e}")
|
93 |
+
return None
|
94 |
|
95 |
|
96 |
|