lichorosario commited on
Commit
8409400
·
1 Parent(s): 95fcad5

feat: Update app.py to enhance image with new options

Browse files
Files changed (1) hide show
  1. app.py +39 -11
app.py CHANGED
@@ -228,30 +228,58 @@ with gr.Blocks(css=css) as demo:
228
 
229
  submit_btn = gr.Button("Submit")
230
  cancel_btn = gr.Button("Cancel")
231
- with gr.Row():
232
- image_out = gr.Image(label="Image output")
233
- image_upscaled = ImageSlider(label="Before / After", type="numpy", show_download_button=False)
234
  scale_btn = gr.Button("Upscale")
235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  selected_index = gr.State(None)
237
 
238
  submit_btn.click(
239
  fn=infer,
240
  inputs=[selected_index, prompt_in, style_prompt_in, inf_steps, guidance_scale, width, height, seed, lora_weight],
241
- outputs=[image_out, last_used_seed, used_prompt]
242
  )
243
  cancel_btn.click(
244
  fn=cancel_infer,
245
  outputs=[]
246
  )
247
 
248
- def upscale_with_fixed_values(image):
249
- return upscale_image(image, 768, 25, 0.4, 0.3, 7.5)
250
-
251
- scale_btn.click(
252
- fn=upscale_with_fixed_values,
253
- inputs=[image_out],
254
- outputs=[image_upscaled]
 
255
  )
256
 
257
 
 
228
 
229
  submit_btn = gr.Button("Submit")
230
  cancel_btn = gr.Button("Cancel")
 
 
 
231
  scale_btn = gr.Button("Upscale")
232
 
233
+
234
+ with gr.Row():
235
+ def clear_output(image_slider):
236
+ image_slider[0] = None
237
+ image_slider[1] = None
238
+ return image_slider
239
+
240
+ with gr.Column():
241
+ generated_image = gr.Image(label="Input Image", type="filepath")
242
+ enhace_button = gr.Button("Enhance Image")
243
+
244
+ with gr.Column():
245
+ output_slider = ImageSlider(label="Before / After", type="numpy", show_download_button=False)
246
+
247
+ with gr.Accordion("Advanced Options", open=False):
248
+ resolution = gr.Slider(minimum=128, maximum=2048, value=1024, step=128, label="Resolution")
249
+ num_inference_steps = gr.Slider(minimum=1, maximum=50, value=20, step=1, label="Number of Inference Steps")
250
+ strength = gr.Slider(minimum=0, maximum=1, value=0.2, step=0.01, label="Strength")
251
+ hdr = gr.Slider(minimum=0, maximum=1, value=0, step=0.1, label="HDR Effect")
252
+ guidance_scale = gr.Slider(minimum=0, maximum=20, value=6, step=0.5, label="Guidance Scale")
253
+ controlnet_strength = gr.Slider(minimum=0.0, maximum=2.0, value=0.75, step=0.05, label="ControlNet Strength")
254
+ scheduler_name = gr.Dropdown(
255
+ choices=["DDIM", "DPM++ 3M SDE Karras", "DPM++ 3M Karras"],
256
+ value="DDIM",
257
+ label="Scheduler"
258
+ )
259
+
260
+
261
+
262
+
263
  selected_index = gr.State(None)
264
 
265
  submit_btn.click(
266
  fn=infer,
267
  inputs=[selected_index, prompt_in, style_prompt_in, inf_steps, guidance_scale, width, height, seed, lora_weight],
268
+ outputs=[generated_image, last_used_seed, used_prompt]
269
  )
270
  cancel_btn.click(
271
  fn=cancel_infer,
272
  outputs=[]
273
  )
274
 
275
+ enhace_button.click(
276
+ fn=clear_output,
277
+ inputs=[output_slider],
278
+ outputs=[output_slider]
279
+ ).then(
280
+ upscale_image,
281
+ [generated_image, resolution, num_inference_steps, strength, hdr, guidance_scale, controlnet_strength, scheduler_name],
282
+ output_slider
283
  )
284
 
285