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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -81
app.py CHANGED
@@ -191,14 +191,89 @@ DEFAULT_VALUES = {
191
  "color_fix_method": "adain"
192
  }
193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  def process_example(img_path, prompt_text, neg_prompt, guid_scale, cond_scale, steps, seed_val, up_factor, color_method):
195
- # Update UI components and process image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  output = process_image(
197
  img_path, prompt_text, neg_prompt, guid_scale,
198
  cond_scale, steps, seed_val, up_factor, color_method
199
  )
200
 
201
- return [
 
202
  img_path, # input_image
203
  prompt_text,
204
  neg_prompt,
@@ -209,9 +284,10 @@ def process_example(img_path, prompt_text, neg_prompt, guid_scale, cond_scale, s
209
  up_factor,
210
  color_method,
211
  img_path, # preview_input
212
- output # output_image
213
  ]
214
 
 
215
  with gr.Blocks(title="Controllable Conditional Super-Resolution") as demo:
216
  gr.Markdown("## Controllable Conditional Super-Resolution")
217
  gr.Markdown("Upload an image to enhance its resolution using CCSR.")
@@ -242,85 +318,40 @@ with gr.Blocks(title="Controllable Conditional Super-Resolution") as demo:
242
  preview_input = gr.Image(label="Preview Input")
243
  output_image = gr.Image(label="Generated Image")
244
 
245
- # Define example data
246
- examples = [
247
- [
248
- "examples/1.png", # Input image path
249
- "clean, texture, high-resolution, 8k", # Prompt
250
- "blurry, dotted, noise, raster lines, unclear, lowres, over-smoothed", # Negative prompt
251
- 3.0, # Guidance scale
252
- 1.0, # Conditioning scale
253
- 6, # Num steps
254
- 42, # Seed
255
- 4, # Upscale factor
256
- "wavelet" # Color fix method
257
- ],
258
- [
259
- "examples/22.png",
260
- "clean, texture, high-resolution, 8k",
261
- "blurry, dotted, noise, raster lines, unclear, lowres, over-smoothed",
262
- 3.0,
263
- 1.0,
264
- 6,
265
- 123,
266
- 4,
267
- "wavelet"
268
- ],
269
- [
270
- "examples/4.png",
271
- "clean, texture, high-resolution, 8k",
272
- "blurry, dotted, noise, raster lines, unclear, lowres, over-smoothed",
273
- 3.0,
274
- 1.0,
275
- 6,
276
- 123,
277
- 4,
278
- "wavelet"
279
- ],
280
- [
281
- "examples/9D03D7F206775949.png",
282
- "clean, texture, high-resolution, 8k",
283
- "blurry, dotted, noise, raster lines, unclear, lowres, over-smoothed",
284
- 3.0,
285
- 1.0,
286
- 6,
287
- 123,
288
- 4,
289
- "wavelet"
290
- ],
291
- [
292
- "examples/3.jpeg",
293
- "clean, texture, high-resolution, 8k",
294
- "blurry, dotted, noise, raster lines, unclear, lowres, over-smoothed",
295
- 2.5,
296
- 1.0,
297
- 6,
298
- 456,
299
- 4,
300
- "wavelet"
301
- ]
302
- ]
303
-
304
  # Add gallery of examples
305
- gr.Examples(
306
- examples=examples,
307
- inputs=[
308
- input_image, prompt, negative_prompt, guidance_scale,
309
- conditioning_scale, num_steps, seed, upscale_factor,
310
- color_fix_method
311
- ],
312
- outputs=[
313
- input_image, prompt, negative_prompt, guidance_scale,
314
- conditioning_scale, num_steps, seed, upscale_factor,
315
- color_fix_method, preview_input, output_image
316
- ],
317
- fn=process_example,
318
- cache_examples=True,
319
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
 
321
- # Define submit action
322
  submit_btn.click(
323
- fn=process_image,
324
  inputs=[
325
  input_image, prompt, negative_prompt, guidance_scale,
326
  conditioning_scale, num_steps, seed, upscale_factor,
@@ -331,7 +362,7 @@ with gr.Blocks(title="Controllable Conditional Super-Resolution") as demo:
331
 
332
  # Add event handler for input image change
333
  def update_preview(img):
334
- return img
335
 
336
  input_image.change(
337
  fn=update_preview,
@@ -367,4 +398,3 @@ with gr.Blocks(title="Controllable Conditional Super-Resolution") as demo:
367
 
368
  if __name__ == "__main__":
369
  demo.launch()
370
-
 
191
  "color_fix_method": "adain"
192
  }
193
 
194
+ # Define example data
195
+ examples = [
196
+ [
197
+ "examples/1.png", # Input image path
198
+ "clean, texture, high-resolution, 8k", # Prompt
199
+ "blurry, dotted, noise, raster lines, unclear, lowres, over-smoothed", # Negative prompt
200
+ 3.0, # Guidance scale
201
+ 1.0, # Conditioning scale
202
+ 6, # Num steps
203
+ 42, # Seed
204
+ 4, # Upscale factor
205
+ "wavelet" # Color fix method
206
+ ],
207
+ [
208
+ "examples/22.png",
209
+ "clean, texture, high-resolution, 8k",
210
+ "blurry, dotted, noise, raster lines, unclear, lowres, over-smoothed",
211
+ 3.0,
212
+ 1.0,
213
+ 6,
214
+ 123,
215
+ 4,
216
+ "wavelet"
217
+ ],
218
+ [
219
+ "examples/4.png",
220
+ "clean, texture, high-resolution, 8k",
221
+ "blurry, dotted, noise, raster lines, unclear, lowres, over-smoothed",
222
+ 3.0,
223
+ 1.0,
224
+ 6,
225
+ 123,
226
+ 4,
227
+ "wavelet"
228
+ ],
229
+ [
230
+ "examples/9D03D7F206775949.png",
231
+ "clean, texture, high-resolution, 8k",
232
+ "blurry, dotted, noise, raster lines, unclear, lowres, over-smoothed",
233
+ 3.0,
234
+ 1.0,
235
+ 6,
236
+ 123,
237
+ 4,
238
+ "wavelet"
239
+ ],
240
+ [
241
+ "examples/3.jpeg",
242
+ "clean, texture, high-resolution, 8k",
243
+ "blurry, dotted, noise, raster lines, unclear, lowres, over-smoothed",
244
+ 2.5,
245
+ 1.0,
246
+ 6,
247
+ 456,
248
+ 4,
249
+ "wavelet"
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,
 
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")
293
  gr.Markdown("Upload an image to enhance its resolution using CCSR.")
 
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,
 
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,
 
398
 
399
  if __name__ == "__main__":
400
  demo.launch()