charliebaby2023 commited on
Commit
b5e8e8c
Β·
verified Β·
1 Parent(s): fa1688f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -18
app.py CHANGED
@@ -57,29 +57,37 @@ def update_imgbox(choices):
57
  executor = ThreadPoolExecutor(max_workers=num_models)
58
 
59
 
 
 
 
 
 
 
 
 
60
  def gen_fn(model_str, prompt):
 
61
  if model_str == 'NA':
62
  return None
63
-
 
64
  noise = str(randint(0, 9999))
65
- combined_prompt = f'{prompt}'
66
- print(f"Generating with prompt: {combined_prompt}")
67
 
68
- try:
69
- image_response = models_load[model_str](f'{prompt} {noise}')
70
- # print(f"77 {models_load[model_str](f'{combined_prompt}')}")
71
- # image_response = models_load[model_str](f'{combined_prompt}')
72
- # Ensure the response is an image or image-like object
73
- if isinstance(image_response, gr.Image):
74
- return image_response
75
- elif isinstance(image_response, str): # If the response is a path or URL, pass it as a string
76
- return gr.Image(image_response) # You can handle it based on your model's return type
77
- else:
78
- print(f"Unexpected response type: {type(image_response)}")
79
- return None
80
- except Exception as e:
81
- print(f"Error occurred: {e}")
82
- return None
83
 
84
 
85
 
 
57
  executor = ThreadPoolExecutor(max_workers=num_models)
58
 
59
 
60
+ #def gen_fn(model_str, prompt):
61
+ # if model_str == 'NA':
62
+ # return None#
63
+ #
64
+ # noise = str(randint(0, 9999))
65
+ # combined_prompt = f'{prompt}'
66
+ # print(f"Generating with prompt: {combined_prompt}")
67
+
68
  def gen_fn(model_str, prompt):
69
+ global models_load
70
  if model_str == 'NA':
71
  return None
72
+ if models_load.get(model_str) is None:
73
+ models_load[model_str] = load_model(model_str) # Load the model if not already loaded
74
  noise = str(randint(0, 9999))
75
+ return models_load[model_str](f'{prompt} {noise}')
76
+
77
 
78
+ # try:
79
+ # image_response = models_load[model_str](f'{prompt} {noise}')
80
+
81
+ # if isinstance(image_response, gr.Image):
82
+ # return image_response
83
+ # elif isinstance(image_response, str): # If the response is a path or URL, pass it as a string
84
+ # return gr.Image(image_response) # You can handle it based on your model's return type
85
+ # else:
86
+ # print(f"Unexpected response type: {type(image_response)}")
87
+ # return None
88
+ # except Exception as e:
89
+ # print(f"Error occurred: {e}")
90
+ # return None
 
 
91
 
92
 
93