Lisandro commited on
Commit
c6f7f75
1 Parent(s): 550b876

chore: Refactor app.py to improve code structure and readability

Browse files
Files changed (1) hide show
  1. app.py +45 -12
app.py CHANGED
@@ -1,17 +1,50 @@
 
1
  from gradio_client import Client, handle_file
 
 
2
  tile_upscaler_url = "gokaygokay/TileUpscalerV2"
3
 
4
  client_tile_upscaler = Client(tile_upscaler_url)
5
 
6
- result = client_tile_upscaler.predict(
7
- param_0=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
8
- param_1=1024,
9
- param_2=20,
10
- param_3=0.2,
11
- param_4=0,
12
- param_5=6,
13
- param_6=0.75,
14
- param_7="DDIM",
15
- api_name="/wrapper"
16
- )
17
- print(result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
  from gradio_client import Client, handle_file
3
+ from gradio_imageslider import ImageSlider
4
+
5
  tile_upscaler_url = "gokaygokay/TileUpscalerV2"
6
 
7
  client_tile_upscaler = Client(tile_upscaler_url)
8
 
9
+ def gradio_process_image(image, resolution, num_inference_steps, strength, hdr, guidance_scale, controlnet_strength, scheduler_name):
10
+ result = client_tile_upscaler.predict(
11
+ param_0=handle_file(image),
12
+ param_1=resolution,
13
+ param_2=num_inference_steps,
14
+ param_3=strength,
15
+ param_4=hdr,
16
+ param_5=guidance_scale,
17
+ param_6=controlnet_strength,
18
+ param_7=scheduler_name,
19
+ api_name="/wrapper"
20
+ )
21
+ return result
22
+
23
+
24
+ with gr.Blocks() as demo:
25
+ with gr.Row():
26
+ with gr.Column():
27
+ input_image = gr.Image(type="pil", label="Input Image")
28
+ run_button = gr.Button("Enhance Image")
29
+ with gr.Column():
30
+ output_slider = ImageSlider(label="Before / After", type="numpy")
31
+ with gr.Accordion("Advanced Options", open=False):
32
+ resolution = gr.Slider(minimum=128, maximum=2048, value=1024, step=128, label="Resolution")
33
+ num_inference_steps = gr.Slider(minimum=1, maximum=50, value=20, step=1, label="Number of Inference Steps")
34
+ strength = gr.Slider(minimum=0, maximum=1, value=0.2, step=0.01, label="Strength")
35
+ hdr = gr.Slider(minimum=0, maximum=1, value=0, step=0.1, label="HDR Effect")
36
+ guidance_scale = gr.Slider(minimum=0, maximum=20, value=6, step=0.5, label="Guidance Scale")
37
+ controlnet_strength = gr.Slider(minimum=0.0, maximum=2.0, value=0.75, step=0.05, label="ControlNet Strength")
38
+ scheduler_name = gr.Dropdown(
39
+ choices=["DDIM", "DPM++ 3M SDE Karras", "DPM++ 3M Karras"],
40
+ value="DDIM",
41
+ label="Scheduler"
42
+ )
43
+
44
+ run_button.click(
45
+ fn=gradio_process_image,
46
+ inputs=[input_image, resolution, num_inference_steps, strength, hdr, guidance_scale, controlnet_strength, scheduler_name],
47
+ outputs=output_slider
48
+ )
49
+
50
+ demo.launch()