addsw11 commited on
Commit
09a787e
1 Parent(s): 9ee67c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -4
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import numpy as np
3
  import random
@@ -24,7 +25,6 @@ COMF_PATH = config('COMF_PATH')
24
 
25
  import torch
26
 
27
- import spaces
28
 
29
  print(f"Is CUDA available: {torch.cuda.is_available()}")
30
  print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
@@ -84,7 +84,7 @@ def check_server_ready(port):
84
 
85
 
86
 
87
- @spaces.GPU(duration=170)
88
  def generate_image(prompt, image):
89
  prefix_filename = str(random.randint(0, 999999))
90
  prompt = prompt.replace('ComfyUI', prefix_filename)
@@ -143,10 +143,96 @@ def generate_image(prompt, image):
143
 
144
 
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  if __name__ == "__main__":
147
- demo = gr.Interface(fn=generate_image, inputs=[
148
  "text",
149
- gr.Image(image_mode='RGBA', type="numpy")
 
150
  ],
151
  outputs=[
152
  gr.Image(type="numpy", image_mode='RGBA')
 
1
+ import spaces
2
  import gradio as gr
3
  import numpy as np
4
  import random
 
25
 
26
  import torch
27
 
 
28
 
29
  print(f"Is CUDA available: {torch.cuda.is_available()}")
30
  print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
 
84
 
85
 
86
 
87
+
88
  def generate_image(prompt, image):
89
  prefix_filename = str(random.randint(0, 999999))
90
  prompt = prompt.replace('ComfyUI', prefix_filename)
 
143
 
144
 
145
 
146
+
147
+ @spaces.GPU(duration=50)
148
+ def generate_image_50(prompt, image):
149
+ return generate_image(prompt, image)
150
+
151
+ @spaces.GPU(duration=70)
152
+ def generate_image_70(prompt, image):
153
+ return generate_image(prompt, image)
154
+
155
+ @spaces.GPU(duration=90)
156
+ def generate_image_90(prompt, image):
157
+ return generate_image(prompt, image)
158
+
159
+ @spaces.GPU(duration=110)
160
+ def generate_image_110(prompt, image):
161
+ return generate_image(prompt, image)
162
+
163
+ @spaces.GPU(duration=130)
164
+ def generate_image_130(prompt, image):
165
+ return generate_image(prompt, image)
166
+
167
+ @spaces.GPU(duration=150)
168
+ def generate_image_150(prompt, image):
169
+ return generate_image(prompt, image)
170
+
171
+ @spaces.GPU(duration=170)
172
+ def generate_image_170(prompt, image):
173
+ return generate_image(prompt, image)
174
+
175
+ @spaces.GPU(duration=190)
176
+ def generate_image_190(prompt, image):
177
+ return generate_image(prompt, image)
178
+
179
+ @spaces.GPU(duration=200)
180
+ def generate_image_200(prompt, image):
181
+ return generate_image(prompt, image)
182
+
183
+ @spaces.GPU(duration=210)
184
+ def generate_image_210(prompt, image):
185
+ return generate_image(prompt, image)
186
+
187
+ @spaces.GPU(duration=220)
188
+ def generate_image_220(prompt, image):
189
+ return generate_image(prompt, image)
190
+
191
+ @spaces.GPU(duration=230)
192
+ def generate_image_230(prompt, image):
193
+ return generate_image(prompt, image)
194
+
195
+ @spaces.GPU(duration=240)
196
+ def generate_image_240(prompt, image):
197
+ return generate_image(prompt, image)
198
+
199
+
200
+ def generate_image_wrapper(prompt, image, duration):
201
+ if duration == "50":
202
+ return generate_image_50(prompt, image)
203
+ elif duration == "70":
204
+ return generate_image_70(prompt, image)
205
+ elif duration == "90":
206
+ return generate_image_90(prompt, image)
207
+ elif duration == "110":
208
+ return generate_image_110(prompt, image)
209
+ elif duration == "130":
210
+ return generate_image_130(prompt, image)
211
+ elif duration == "150":
212
+ return generate_image_150(prompt, image)
213
+ elif duration == "170":
214
+ return generate_image_170(prompt, image)
215
+ elif duration == "190":
216
+ return generate_image_190(prompt, image)
217
+ elif duration == "200":
218
+ return generate_image_200(prompt, image)
219
+ elif duration == "210":
220
+ return generate_image_210(prompt, image)
221
+ elif duration == "220":
222
+ return generate_image_220(prompt, image)
223
+ elif duration == "230":
224
+ return generate_image_230(prompt, image)
225
+ elif duration == "240":
226
+ return generate_image_240(prompt, image)
227
+ else:
228
+ return generate_image_170(prompt, image)
229
+
230
+
231
  if __name__ == "__main__":
232
+ demo = gr.Interface(fn=generate_image_wrapper, inputs=[
233
  "text",
234
+ gr.Image(image_mode='RGBA', type="numpy"),
235
+ "text"
236
  ],
237
  outputs=[
238
  gr.Image(type="numpy", image_mode='RGBA')