init app
Browse files- main.py +96 -0
- requirements.txt +1 -0
main.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
+
|
4 |
+
clientGFPGAN = Client("leonelhs/GFPGAN")
|
5 |
+
clientZeroScratches = Client("leonelhs/ZeroScratches")
|
6 |
+
clientDeoldify = Client("leonelhs/deoldify")
|
7 |
+
clientEnhanceLight = Client("leonelhs/Zero-DCE")
|
8 |
+
clientZeroBackground = Client("leonelhs/ZeroBackground")
|
9 |
+
clientFaceParser = Client("leonelhs/faceparser")
|
10 |
+
|
11 |
+
|
12 |
+
def enhance_face(image):
|
13 |
+
return clientGFPGAN.predict(image, "v1.4", "2", api_name="/predict")[1]
|
14 |
+
|
15 |
+
|
16 |
+
def zero_scratches(image):
|
17 |
+
return clientZeroScratches.predict(image, api_name="/predict")
|
18 |
+
|
19 |
+
|
20 |
+
def colorize_photo(image):
|
21 |
+
return clientDeoldify.predict(image, api_name="/predict")
|
22 |
+
|
23 |
+
|
24 |
+
def enhance_light(image):
|
25 |
+
return clientEnhanceLight.predict(image, api_name="/predict")
|
26 |
+
|
27 |
+
|
28 |
+
def zero_background(image, new_bgr):
|
29 |
+
return clientZeroBackground.predict(image, new_bgr, api_name="/predict")
|
30 |
+
|
31 |
+
|
32 |
+
def parse_face(image):
|
33 |
+
return clientFaceParser.predict(image, api_name="/predict")
|
34 |
+
|
35 |
+
|
36 |
+
def mirror(x):
|
37 |
+
return x
|
38 |
+
|
39 |
+
|
40 |
+
footer = r"""
|
41 |
+
<center>
|
42 |
+
<p>This App is running on a CPU, help us to upgrade a GPU or just give us a <a href='https://github.com/leonelhs/face-shine' target='_blank'>Github ⭐</a></p>
|
43 |
+
</br>
|
44 |
+
<a href="https://www.buymeacoffee.com/leonelhs">
|
45 |
+
<img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=leonelhs&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff" />
|
46 |
+
</a>
|
47 |
+
</center>
|
48 |
+
</br>
|
49 |
+
<center><span>[email protected]</span></center>
|
50 |
+
"""
|
51 |
+
|
52 |
+
with gr.Blocks() as app:
|
53 |
+
with gr.Tab("Face Shine"):
|
54 |
+
with gr.Row():
|
55 |
+
with gr.Column(scale=1):
|
56 |
+
btn_hires = gr.Button(value="Enhance resolution")
|
57 |
+
btn_eraser = gr.Button(value="Erase scratches")
|
58 |
+
btn_color = gr.Button(value="Colorize photo")
|
59 |
+
btn_light = gr.Button(value="Enhance light")
|
60 |
+
with gr.Accordion("Clear background", open=False):
|
61 |
+
btn_clear = gr.Button(value="Clear background")
|
62 |
+
# chk_newbgr = gr.Checkbox(label="Change background")
|
63 |
+
img_newbgr = gr.Image(label="Choose file for new background", type="filepath")
|
64 |
+
|
65 |
+
with gr.Column(scale=4):
|
66 |
+
with gr.Row():
|
67 |
+
img_input = gr.Image(label="Input", type="filepath")
|
68 |
+
img_output = gr.Image(label="Result", type="filepath", interactive=False)
|
69 |
+
|
70 |
+
with gr.Row():
|
71 |
+
btn_swap = gr.Button(value="Swap images")
|
72 |
+
btn_reset = gr.Button("Clear")
|
73 |
+
|
74 |
+
btn_hires.click(enhance_face, inputs=[img_input], outputs=[img_output])
|
75 |
+
btn_eraser.click(zero_scratches, inputs=[img_input], outputs=[img_output])
|
76 |
+
btn_color.click(colorize_photo, inputs=[img_input], outputs=[img_output])
|
77 |
+
btn_light.click(enhance_light, inputs=[img_input], outputs=[img_output])
|
78 |
+
btn_clear.click(zero_background, inputs=[img_input, img_newbgr], outputs=[img_output])
|
79 |
+
btn_swap.click(mirror, inputs=[img_output], outputs=[img_input])
|
80 |
+
btn_reset.click(lambda: None, None, img_input, queue=False)
|
81 |
+
|
82 |
+
with gr.Tab("Settings"):
|
83 |
+
with gr.Accordion("Real-ESRGAN: Practical Image/Video Restoration. ", open=False):
|
84 |
+
gr.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer'], type="value", label='version')
|
85 |
+
with gr.Accordion("GFPGAN: Practical Face Restoration Algorithm", open=False):
|
86 |
+
gr.Checkbox(label="Include false", info="Extra process for face enhancement")
|
87 |
+
gr.Radio(['v1.2', 'v1.3', 'v1.4', 'RestoreFormer'], type="value", label='version')
|
88 |
+
gr.Dropdown(
|
89 |
+
["1", "2", "3", "4"], label="Scale", info="Select output scale"
|
90 |
+
)
|
91 |
+
gr.Button("Save settings")
|
92 |
+
|
93 |
+
with gr.Row():
|
94 |
+
gr.HTML(footer)
|
95 |
+
|
96 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gradio
|