charliebaby2023 commited on
Commit
9534b33
Β·
verified Β·
1 Parent(s): e1f04d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -11
app.py CHANGED
@@ -3,6 +3,7 @@ from random import randint
3
  from all_models import models
4
  from datetime import datetime
5
  from concurrent.futures import ThreadPoolExecutor
 
6
 
7
  now2 = 0
8
  kii=" mohawk femboy racecar driver ";
@@ -33,6 +34,14 @@ load_fn(models)
33
  num_models = len(models)
34
  default_models = models[:num_models]
35
 
 
 
 
 
 
 
 
 
36
  def extend_choices(choices):
37
  return choices + (num_models - len(choices)) * ['NA']
38
 
@@ -40,9 +49,6 @@ def update_imgbox(choices):
40
  choices_plus = extend_choices(choices)
41
  return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
42
 
43
- def gen_fn(model_str, prompt, negative_prompt):
44
- if model_str == 'NA':
45
- return None
46
 
47
  executor = ThreadPoolExecutor(max_workers=num_models)
48
 
@@ -53,13 +59,18 @@ def gen_fn(model_str, prompt, negative_prompt):
53
  noise = str(randint(0, 9999))
54
  combined_prompt = f'{prompt} {model_str} {negative_prompt} {noise}'
55
  print(f"Generating with prompt: {combined_prompt}")
56
-
57
- # Use the executor to run models in parallel
58
- future = executor.submit(models_load[model_str], f'{prompt} {negative_prompt} {noise}')
59
- result = future.result()
60
- return result
61
-
62
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
 
65
  # noise = str(randint(0, 9999))
@@ -83,6 +94,10 @@ def gen_fn(model_str, prompt, negative_prompt):
83
 
84
 
85
 
 
 
 
 
86
  def make_me():
87
  # with gr.Tab('The Dream'):
88
  with gr.Row():
@@ -91,7 +106,7 @@ def make_me():
91
  negative_prompt_input = gr.Textbox(lines=2, value="", label="Negative Prompt" )
92
  gen_button = gr.Button('Generate images')
93
  stop_button = gr.Button('Stop', variant='secondary', interactive=False)
94
- gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
95
  gr.HTML("""
96
  <div style="text-align: center; max-width: 100%; margin: 0 auto;">
97
  <body>
@@ -103,7 +118,7 @@ def make_me():
103
  current_models = [gr.Textbox(m, visible=False) for m in default_models]
104
  for m, o in zip(current_models, output):
105
  gen_event = gen_button.click(gen_fn, [m, txt_input, negative_prompt_input], o)
106
- stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
107
 
108
 
109
  with gr.Accordion('Model selection'):
@@ -138,6 +153,22 @@ js_code = """
138
 
139
 
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  with gr.Blocks(css="""
142
  label.float.svelte-i3tvor { top:auto!important; bottom: 0; position: absolute; background: rgba(0,0,0,0.0); left: var(--block-label-margin); color: rgba(200,200,200,.7);}
143
  .genbut { max-width: 50px; max-height: 30px; width:150px; height:30px}
 
3
  from all_models import models
4
  from datetime import datetime
5
  from concurrent.futures import ThreadPoolExecutor
6
+ import requests
7
 
8
  now2 = 0
9
  kii=" mohawk femboy racecar driver ";
 
34
  num_models = len(models)
35
  default_models = models[:num_models]
36
 
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
  def extend_choices(choices):
46
  return choices + (num_models - len(choices)) * ['NA']
47
 
 
49
  choices_plus = extend_choices(choices)
50
  return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
51
 
 
 
 
52
 
53
  executor = ThreadPoolExecutor(max_workers=num_models)
54
 
 
59
  noise = str(randint(0, 9999))
60
  combined_prompt = f'{prompt} {model_str} {negative_prompt} {noise}'
61
  print(f"Generating with prompt: {combined_prompt}")
 
 
 
 
 
 
62
 
63
+ try:
64
+ future = executor.submit(models_load[model_str], f'{prompt} {negative_prompt} {noise}')
65
+ result = future.result()
66
+ return result
67
+ except requests.exceptions.Timeout:
68
+ print(f"Timeout occurred for model {model_str}. Please try again later.")
69
+ return None
70
+ except Exception as e:
71
+ print(f"Error occurred: {e}")
72
+ return None
73
+
74
 
75
 
76
  # noise = str(randint(0, 9999))
 
94
 
95
 
96
 
97
+
98
+
99
+
100
+
101
  def make_me():
102
  # with gr.Tab('The Dream'):
103
  with gr.Row():
 
106
  negative_prompt_input = gr.Textbox(lines=2, value="", label="Negative Prompt" )
107
  gen_button = gr.Button('Generate images')
108
  stop_button = gr.Button('Stop', variant='secondary', interactive=False)
109
+ gen_button.click(lambda _: gr.update(interactive=True), None, stop_button)
110
  gr.HTML("""
111
  <div style="text-align: center; max-width: 100%; margin: 0 auto;">
112
  <body>
 
118
  current_models = [gr.Textbox(m, visible=False) for m in default_models]
119
  for m, o in zip(current_models, output):
120
  gen_event = gen_button.click(gen_fn, [m, txt_input, negative_prompt_input], o)
121
+ stop_button.click(lambda _: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
122
 
123
 
124
  with gr.Accordion('Model selection'):
 
153
 
154
 
155
 
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
  with gr.Blocks(css="""
173
  label.float.svelte-i3tvor { top:auto!important; bottom: 0; position: absolute; background: rgba(0,0,0,0.0); left: var(--block-label-margin); color: rgba(200,200,200,.7);}
174
  .genbut { max-width: 50px; max-height: 30px; width:150px; height:30px}