Update app.py
Browse files
app.py
CHANGED
@@ -30,22 +30,27 @@ class ModelGenerator:
|
|
30 |
api_name="/run"
|
31 |
)
|
32 |
|
33 |
-
# Handle
|
34 |
-
if isinstance(result,
|
35 |
-
# If
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
image_data = result[0]
|
37 |
-
if isinstance(image_data,
|
38 |
-
|
39 |
-
# If it's a URL, download the image
|
40 |
-
response = requests.get(image_data)
|
41 |
-
image = Image.open(io.BytesIO(response.content))
|
42 |
-
else:
|
43 |
-
# If it's a file path
|
44 |
-
image = Image.open(image_data)
|
45 |
else:
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
49 |
else:
|
50 |
return ("Midjourney", f"Error: Unexpected result format: {type(result)}")
|
51 |
except Exception as e:
|
|
|
30 |
api_name="/run"
|
31 |
)
|
32 |
|
33 |
+
# Handle different types of results
|
34 |
+
if isinstance(result, tuple):
|
35 |
+
# If it's a tuple, the first element might be the image gallery
|
36 |
+
if len(result) > 0 and isinstance(result[0], list):
|
37 |
+
image_data = result[0][0] # Get first image from gallery
|
38 |
+
if isinstance(image_data, dict) and 'image' in image_data:
|
39 |
+
return ("Midjourney", image_data['image'])
|
40 |
+
elif isinstance(image_data, (str, bytes)):
|
41 |
+
return ("Midjourney", image_data)
|
42 |
+
else:
|
43 |
+
return ("Midjourney", result[0]) # Try first element of tuple
|
44 |
+
elif isinstance(result, list) and len(result) > 0:
|
45 |
+
# If it's a list, get the first element
|
46 |
image_data = result[0]
|
47 |
+
if isinstance(image_data, dict) and 'image' in image_data:
|
48 |
+
return ("Midjourney", image_data['image'])
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
else:
|
50 |
+
return ("Midjourney", image_data)
|
51 |
+
elif isinstance(result, str):
|
52 |
+
# If it's a direct string (URL or path)
|
53 |
+
return ("Midjourney", result)
|
54 |
else:
|
55 |
return ("Midjourney", f"Error: Unexpected result format: {type(result)}")
|
56 |
except Exception as e:
|