awacke1 commited on
Commit
7711cae
1 Parent(s): 35bb627

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -3,6 +3,9 @@ from gradio_client import Client
3
  import time
4
  import concurrent.futures
5
  import os
 
 
 
6
 
7
  # Get token from environment variable
8
  HF_TOKEN = os.getenv('ArtToken')
@@ -26,7 +29,25 @@ class ModelGenerator:
26
  randomize_seed=True,
27
  api_name="/run"
28
  )
29
- return ("Midjourney", result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  except Exception as e:
31
  return ("Midjourney", f"Error: {str(e)}")
32
 
@@ -251,7 +272,8 @@ def main():
251
  if isinstance(result, str) and result.startswith("Error"):
252
  st.error(result)
253
  else:
254
- st.image(result, use_column_width=True)
 
255
 
256
  if __name__ == "__main__":
257
  main()
 
3
  import time
4
  import concurrent.futures
5
  import os
6
+ from PIL import Image
7
+ import io
8
+ import requests
9
 
10
  # Get token from environment variable
11
  HF_TOKEN = os.getenv('ArtToken')
 
29
  randomize_seed=True,
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:
52
  return ("Midjourney", f"Error: {str(e)}")
53
 
 
272
  if isinstance(result, str) and result.startswith("Error"):
273
  st.error(result)
274
  else:
275
+ # Updated to use use_container_width instead of use_column_width
276
+ st.image(result, use_container_width=True)
277
 
278
  if __name__ == "__main__":
279
  main()