DmitrMakeev commited on
Commit
c9f3f27
1 Parent(s): 760c6c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -34
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.Interface(title="DISCO",
39
- description='Gradio demo for DISCO: Disentangled Image Colorization via Global Anchors. Check our project page 😛.',
40
- inputs=[gr.inputs.Image(type="numpy", label="Input", interactive=True)],
41
- outputs=[gr.outputs.Image(label="Output")])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
- demo.layout = gr.Interface.Layout(
44
- gr.Interface.Panel("Anchor",
45
- [
46
- gr.inputs.Image(type="numpy", label="Anchor", tool="color-sketch", interactive=True, visible=False).style(width="600px", height="600px"),
47
- gr.inputs.Checkbox(default=False, label='Show editable anchors'),
48
- gr.inputs.Button(value="Predict anchors", visible=False)
49
- ]),
50
- gr.Interface.Panel("Settings",
51
- [
52
- gr.inputs.Number(type="int", value=8, label="Количество опорных точек (3~14)"),
53
- gr.inputs.Radio(type="index", choices=["Low (256x256)", "Medium (512x512)", "High (1024x1024)"], label="Область для раскрашивания кистью", value="Low (256x256)")
54
- ]),
55
- gr.Interface.Panel("Result",
56
- [
57
- gr.outputs.Image(label="Output"),
58
- gr.outputs.Image(label="Output")
59
- ])
60
- )
61
-
62
- def click_predanchors(rgb_img, n_anchors, is_high_res, is_editable):
63
- output = predict_anchors(colorizer, colorLabeler, rgb_img, n_anchors, is_high_res, is_editable, device)
64
- return output
65
-
66
- def click_colorize(rgb_img, hint_img, n_anchors, is_high_res, is_editable):
67
- if hint_img is None:
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
- demo.launch()
 
 
 
 
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()