DmitrMakeev
commited on
Commit
•
c9f3f27
1
Parent(s):
760c6c0
Update app.py
Browse files
app.py
CHANGED
@@ -35,39 +35,54 @@ def switch_states(is_checked):
|
|
35 |
else:
|
36 |
return gr.Image.update(visible=False), gr.Button.update(visible=False)
|
37 |
|
38 |
-
demo = gr.
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
)
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
hint_img = rgb_img
|
69 |
-
output = colorize_grayscale(colorizer, colorLabeler, rgb_img, hint_img, n_anchors, True, is_editable, device)
|
70 |
-
output1 = colorize_grayscale(colorizer, colorLabeler, rgb_img, hint_img, n_anchors, False, is_editable, device)
|
71 |
-
return output, output1
|
72 |
|
73 |
-
|
|
|
|
|
|
|
|
35 |
else:
|
36 |
return gr.Image.update(visible=False), gr.Button.update(visible=False)
|
37 |
|
38 |
+
demo = gr.Blocks(title="DISCO")
|
39 |
+
with demo:
|
40 |
+
gr.Markdown(value="""
|
41 |
+
**Gradio demo for DISCO: Disentangled Image Colorization via Global Anchors**. Check our [project page](https://menghanxia.github.io/projects/disco.html) 😛.
|
42 |
+
""")
|
43 |
+
with gr.Row():
|
44 |
+
with gr.Column():
|
45 |
+
with gr.Row().style(height=480):
|
46 |
+
Image_input = gr.Image(type="numpy", label="Input", interactive=True)
|
47 |
+
Image_anchor = gr.Image(type="numpy", label="Anchor", tool="color-sketch", interactive=True, visible=False)
|
48 |
+
with gr.Row():
|
49 |
+
Num_anchor = gr.Number(type="int", value=8, label="Num. of anchors (3~14)")
|
50 |
+
Radio_resolution = gr.Radio(type="index", choices=["Low (256x256)", "High (512x512)"], \
|
51 |
+
label="Colorization resolution (Low is more stable)", value="Low (256x256)")
|
52 |
+
with gr.Row():
|
53 |
+
Ckeckbox_editable = gr.Checkbox(default=False, label='Show editable anchors')
|
54 |
+
Button_show_anchor = gr.Button(value="Predict anchors", visible=False)
|
55 |
+
Button_run = gr.Button(value="Colorize")
|
56 |
+
with gr.Column():
|
57 |
+
Image_output = gr.Image(type="numpy", label="Output").style(height=480)
|
58 |
|
59 |
+
Ckeckbox_editable.change(fn=switch_states, inputs=Ckeckbox_editable, outputs=[Image_anchor, Button_show_anchor])
|
60 |
+
Button_show_anchor.click(fn=click_predanchors, inputs=[Image_input, Num_anchor, Radio_resolution, Ckeckbox_editable], outputs=Image_anchor)
|
61 |
+
Button_run.click(fn=click_colorize, inputs=[Image_input, Image_anchor, Num_anchor, Radio_resolution, Ckeckbox_editable], \
|
62 |
+
outputs=Image_output)
|
63 |
+
|
64 |
+
## guiline
|
65 |
+
gr.Markdown(value="""
|
66 |
+
🔔**Guideline**
|
67 |
+
1. Upload your image or select one from the examples.
|
68 |
+
2. Set up the arguments: "Num. of anchors" and "Colorization resolution".
|
69 |
+
3. Run the colorization (two modes supported):
|
70 |
+
- 📀Automatic mode: **Click** "Colorize" to get the automatically colorized output.
|
71 |
+
- ✏️Editable mode: **Check** ""Show editable anchors"; **Click** "Predict anchors"; **Redraw** the anchor colors (only anchor region will be used); **Click** "Colorize" to get the result.
|
72 |
+
""")
|
73 |
+
if RUN_MODE != "local":
|
74 |
+
gr.Examples(examples=[
|
75 |
+
['01.jpg', 8, "Low (256x256)"],
|
76 |
+
['02.jpg', 8, "Low (256x256)"],
|
77 |
+
['03.jpg', 8, "Low (256x256)"],
|
78 |
+
['04.jpg', 8, "Low (256x256)"],
|
79 |
+
],
|
80 |
+
inputs=[Image_input,Num_anchor,Radio_resolution], outputs=[Image_output], label="Examples")
|
81 |
+
gr.HTML(value="""
|
82 |
+
<p style="text-align:center; color:orange"><a href='https://menghanxia.github.io/projects/disco.html' target='_blank'>DISCO Project Page</a> | <a href='https://github.com/MenghanXia/DisentangledColorization' target='_blank'>Github Repo</a></p>
|
83 |
+
""")
|
|
|
|
|
|
|
|
|
84 |
|
85 |
+
if RUN_MODE == "local":
|
86 |
+
demo.launch(server_name='9.134.253.83',server_port=7788)
|
87 |
+
else:
|
88 |
+
demo.launch()
|