ford442 commited on
Commit
c53362d
·
1 Parent(s): 2dd9809

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -75
app.py CHANGED
@@ -124,7 +124,7 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
124
  seed = random.randint(0, MAX_SEED)
125
  return seed
126
 
127
- @spaces.GPU(duration=70, enable_queue=True)
128
  def generate(
129
  model_choice: str,
130
  prompt: str,
@@ -143,56 +143,7 @@ def generate(
143
  ):
144
  global models
145
  pipe = models[model_choice]
146
- seed = int(randomize_seed_fn(seed, randomize_seed))
147
- generator = torch.Generator(device=device).manual_seed(seed)
148
-
149
- prompt, negative_prompt = apply_style(style_selection, prompt, negative_prompt)
150
-
151
- options = {
152
- "prompt": [prompt] * num_images,
153
- "negative_prompt": [negative_prompt] * num_images if use_negative_prompt else None,
154
- "width": width,
155
- "height": height,
156
- "guidance_scale": guidance_scale,
157
- "num_inference_steps": num_inference_steps,
158
- "generator": generator,
159
- "output_type": "pil",
160
- }
161
-
162
- if use_resolution_binning:
163
- options["use_resolution_binning"] = True
164
-
165
- images = []
166
- for i in range(0, num_images, BATCH_SIZE):
167
- batch_options = options.copy()
168
- batch_options["prompt"] = options["prompt"][i:i+BATCH_SIZE]
169
- if "negative_prompt" in batch_options:
170
- batch_options["negative_prompt"] = options["negative_prompt"][i:i+BATCH_SIZE]
171
- images.extend(pipe(**batch_options).images)
172
-
173
- image_paths = [save_image(img) for img in images]
174
- return image_paths, seed
175
-
176
- def generate_cpu(
177
- model_choice: str,
178
- prompt: str,
179
- negative_prompt: str = "",
180
- use_negative_prompt: bool = False,
181
- style_selection: str = DEFAULT_STYLE_NAME,
182
- seed: int = 1,
183
- width: int = 768,
184
- height: int = 768,
185
- guidance_scale: float = 4,
186
- num_inference_steps: int = 150,
187
- randomize_seed: bool = False,
188
- use_resolution_binning: bool = True,
189
- num_images: int = 1,
190
- progress=gr.Progress(track_tqdm=True),
191
- ):
192
- global models
193
- pipe = models[model_choice]
194
- pipe.to("cpu")
195
-
196
  seed = int(randomize_seed_fn(seed, randomize_seed))
197
  generator = torch.Generator(device=device).manual_seed(seed)
198
 
@@ -264,7 +215,6 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
264
  container=False,
265
  )
266
  run_button = gr.Button("Run", scale=0)
267
- cpu_run_button = gr.Button("CPU Run", scale=0)
268
  result = gr.Gallery(label="Result", columns=1, show_label=False)
269
 
270
  with gr.Row():
@@ -378,29 +328,6 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
378
  outputs=[result, seed],
379
  )
380
 
381
- gr.on(
382
- triggers=[
383
- cpu_run_button.click,
384
- ],
385
- api_name="generate", # Add this line
386
- fn=generate_cpu,
387
- inputs=[
388
- model_choice,
389
- prompt,
390
- negative_prompt,
391
- use_negative_prompt,
392
- style_selection,
393
- seed,
394
- width,
395
- height,
396
- guidance_scale,
397
- num_inference_steps,
398
- randomize_seed,
399
- num_images,
400
- ],
401
- outputs=[result, seed],
402
- )
403
-
404
  gr.Markdown("### REALVISXL V5.0")
405
  predefined_gallery = gr.Gallery(label="REALVISXL V5.0", columns=3, show_label=False, value=load_predefined_images1())
406
 
 
124
  seed = random.randint(0, MAX_SEED)
125
  return seed
126
 
127
+ @spaces.GPU(duration=40, enable_queue=True)
128
  def generate(
129
  model_choice: str,
130
  prompt: str,
 
143
  ):
144
  global models
145
  pipe = models[model_choice]
146
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  seed = int(randomize_seed_fn(seed, randomize_seed))
148
  generator = torch.Generator(device=device).manual_seed(seed)
149
 
 
215
  container=False,
216
  )
217
  run_button = gr.Button("Run", scale=0)
 
218
  result = gr.Gallery(label="Result", columns=1, show_label=False)
219
 
220
  with gr.Row():
 
328
  outputs=[result, seed],
329
  )
330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
  gr.Markdown("### REALVISXL V5.0")
332
  predefined_gallery = gr.Gallery(label="REALVISXL V5.0", columns=3, show_label=False, value=load_predefined_images1())
333