awacke1 commited on
Commit
69683d3
1 Parent(s): d305af7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -30,22 +30,27 @@ class ModelGenerator:
30
  api_name="/run"
31
  )
32
 
33
- # Handle the result based on its type
34
- if isinstance(result, list) and len(result) > 0:
35
- # If result is a list of file paths or URLs
 
 
 
 
 
 
 
 
 
 
36
  image_data = result[0]
37
- if isinstance(image_data, str):
38
- if image_data.startswith('http'):
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
- # If it's already image data
47
- image = Image.open(io.BytesIO(image_data))
48
- return ("Midjourney", image)
 
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: