NightRaven109 commited on
Commit
af44365
1 Parent(s): 5d6e388

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -86
app.py CHANGED
@@ -192,7 +192,7 @@ DEFAULT_VALUES = {
192
  }
193
 
194
  # Define example data
195
- examples = [
196
  [
197
  "examples/1.png", # Input image path
198
  "clean, texture, high-resolution, 8k", # Prompt
@@ -250,43 +250,6 @@ examples = [
250
  ]
251
  ]
252
 
253
- def process_example(img_path, prompt_text, neg_prompt, guid_scale, cond_scale, steps, seed_val, up_factor, color_method):
254
- # First update the input fields and preview
255
- yield [
256
- img_path, # input_image
257
- prompt_text,
258
- neg_prompt,
259
- guid_scale,
260
- cond_scale,
261
- steps,
262
- seed_val,
263
- up_factor,
264
- color_method,
265
- img_path, # preview_input
266
- gr.update(value=None, label="Processing...") # output_image
267
- ]
268
-
269
- # Process the image
270
- output = process_image(
271
- img_path, prompt_text, neg_prompt, guid_scale,
272
- cond_scale, steps, seed_val, up_factor, color_method
273
- )
274
-
275
- # Return final result
276
- yield [
277
- img_path, # input_image
278
- prompt_text,
279
- neg_prompt,
280
- guid_scale,
281
- cond_scale,
282
- steps,
283
- seed_val,
284
- up_factor,
285
- color_method,
286
- img_path, # preview_input
287
- gr.update(value=output, label="Generated Image") # output_image
288
- ]
289
-
290
  # Create interface components
291
  with gr.Blocks(title="Controllable Conditional Super-Resolution") as demo:
292
  gr.Markdown("## Controllable Conditional Super-Resolution")
@@ -315,43 +278,24 @@ with gr.Blocks(title="Controllable Conditional Super-Resolution") as demo:
315
  submit_btn = gr.Button("Submit", variant="primary")
316
 
317
  with gr.Column():
318
- preview_input = gr.Image(label="Preview Input")
319
  output_image = gr.Image(label="Generated Image")
320
 
321
- # Add gallery of examples
322
- with gr.Row():
323
- gr.Examples(
324
- examples=examples,
325
- inputs=[
326
- input_image, prompt, negative_prompt, guidance_scale,
327
- conditioning_scale, num_steps, seed, upscale_factor,
328
- color_fix_method
329
- ],
330
- outputs=[
331
- input_image, prompt, negative_prompt, guidance_scale,
332
- conditioning_scale, num_steps, seed, upscale_factor,
333
- color_fix_method, preview_input, output_image
334
- ],
335
- fn=process_example,
336
- cache_examples=True,
337
- )
338
-
339
- # Define submit action with progress
340
- def process_with_progress(img, prompt_text, neg_prompt, guid_scale, cond_scale, steps, seed_val, up_factor, color_method):
341
- # Update UI to show processing state
342
- yield gr.update(value=None, label="Processing...")
343
-
344
- # Process image
345
- result = process_image(
346
- img, prompt_text, neg_prompt, guid_scale,
347
- cond_scale, steps, seed_val, up_factor, color_method
348
- )
349
-
350
- # Return final result
351
- yield gr.update(value=result, label="Generated Image")
352
 
 
353
  submit_btn.click(
354
- fn=process_with_progress,
355
  inputs=[
356
  input_image, prompt, negative_prompt, guidance_scale,
357
  conditioning_scale, num_steps, seed, upscale_factor,
@@ -360,16 +304,6 @@ with gr.Blocks(title="Controllable Conditional Super-Resolution") as demo:
360
  outputs=output_image
361
  )
362
 
363
- # Add event handler for input image change
364
- def update_preview(img):
365
- return img if img is not None else None
366
-
367
- input_image.change(
368
- fn=update_preview,
369
- inputs=input_image,
370
- outputs=preview_input
371
- )
372
-
373
  # Define clear action that resets to default values
374
  def reset_to_defaults():
375
  return [
@@ -381,9 +315,7 @@ with gr.Blocks(title="Controllable Conditional Super-Resolution") as demo:
381
  DEFAULT_VALUES["num_steps"],
382
  DEFAULT_VALUES["seed"],
383
  DEFAULT_VALUES["upscale_factor"],
384
- DEFAULT_VALUES["color_fix_method"],
385
- None, # preview_input
386
- None # output_image
387
  ]
388
 
389
  clear_btn.click(
@@ -392,9 +324,9 @@ with gr.Blocks(title="Controllable Conditional Super-Resolution") as demo:
392
  outputs=[
393
  input_image, prompt, negative_prompt, guidance_scale,
394
  conditioning_scale, num_steps, seed, upscale_factor,
395
- color_fix_method, preview_input, output_image
396
  ]
397
  )
398
 
399
  if __name__ == "__main__":
400
- demo.launch()
 
192
  }
193
 
194
  # Define example data
195
+ EXAMPLES = [
196
  [
197
  "examples/1.png", # Input image path
198
  "clean, texture, high-resolution, 8k", # Prompt
 
250
  ]
251
  ]
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  # Create interface components
254
  with gr.Blocks(title="Controllable Conditional Super-Resolution") as demo:
255
  gr.Markdown("## Controllable Conditional Super-Resolution")
 
278
  submit_btn = gr.Button("Submit", variant="primary")
279
 
280
  with gr.Column():
 
281
  output_image = gr.Image(label="Generated Image")
282
 
283
+ # Add examples
284
+ gr.Examples(
285
+ examples=EXAMPLES,
286
+ inputs=[
287
+ input_image, prompt, negative_prompt, guidance_scale,
288
+ conditioning_scale, num_steps, seed, upscale_factor,
289
+ color_fix_method
290
+ ],
291
+ outputs=output_image,
292
+ fn=process_image,
293
+ cache_examples=True # Cache the results for faster loading
294
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
 
296
+ # Define submit action
297
  submit_btn.click(
298
+ fn=process_image,
299
  inputs=[
300
  input_image, prompt, negative_prompt, guidance_scale,
301
  conditioning_scale, num_steps, seed, upscale_factor,
 
304
  outputs=output_image
305
  )
306
 
 
 
 
 
 
 
 
 
 
 
307
  # Define clear action that resets to default values
308
  def reset_to_defaults():
309
  return [
 
315
  DEFAULT_VALUES["num_steps"],
316
  DEFAULT_VALUES["seed"],
317
  DEFAULT_VALUES["upscale_factor"],
318
+ DEFAULT_VALUES["color_fix_method"]
 
 
319
  ]
320
 
321
  clear_btn.click(
 
324
  outputs=[
325
  input_image, prompt, negative_prompt, guidance_scale,
326
  conditioning_scale, num_steps, seed, upscale_factor,
327
+ color_fix_method
328
  ]
329
  )
330
 
331
  if __name__ == "__main__":
332
+ demo.launch()