Spaces:
Sleeping
Sleeping
chore: Refactor app.py to improve code structure and readability
Browse files
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 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|