charliebaby2023 commited on
Commit
2eb1abd
Β·
verified Β·
1 Parent(s): e96189e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -21,13 +21,34 @@ def load_fn(models):
21
  models_load = {}
22
  for model in models:
23
  if model not in models_load.keys():
 
 
 
 
 
 
24
  try:
25
- m = gr.load(f'models/{model}')
26
- except Exception as error:
27
- print(f"Error loading model {model}: {error}")
28
- m = gr.Interface(lambda _: None, inputs=gr.Textbox(), outputs=gr.Image(), enable_queue=False)
29
- models_load.update({model: m})
30
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  load_fn(models)
33
 
 
21
  models_load = {}
22
  for model in models:
23
  if model not in models_load.keys():
24
+ # try:
25
+ # m = gr.load(f'models/{model}')
26
+ # except Exception as error:
27
+ # print(f"Error loading model {model}: {error}")
28
+ # m = gr.Interface(lambda _: None, inputs=gr.Textbox(), outputs=gr.Image(), enable_queue=False)
29
+ # models_load.update({model: m})
30
  try:
31
+ # Attempt to generate the image
32
+ image_response = models_load[model_str](f'{prompt} {negative_prompt} {noise}')
33
+
34
+ # Check if the image_response is a tuple, handle accordingly
35
+ if isinstance(image_response, tuple):
36
+ # If the response is a tuple, return the first item assuming it's the image
37
+ image_response = image_response[0]
38
+
39
+ # Ensure the response is an image or image-like object
40
+ if isinstance(image_response, gr.Image):
41
+ return image_response
42
+ elif isinstance(image_response, str): # If the response is a path or URL, pass it as a string
43
+ return gr.Image(image_response) # You can handle it based on your model's return type
44
+ else:
45
+ print(f"Unexpected response type: {type(image_response)}")
46
+ return None
47
+
48
+ except Exception as e:
49
+ print(f"Error occurred: {e}")
50
+ return None
51
+
52
 
53
  load_fn(models)
54