|
import gradio as gr |
|
from gradio_client import Client |
|
|
|
clientGFPGAN = Client("leonelhs/GFPGAN") |
|
clientSuperface = Client("leonelhs/superface") |
|
clientZeroScratches = Client("leonelhs/ZeroScratches") |
|
clientDeoldify = Client("leonelhs/deoldify") |
|
clientEnhanceLight = Client("leonelhs/Zero-DCE") |
|
clientZeroBackground = Client("leonelhs/ZeroBackground") |
|
clientFaceParser = Client("leonelhs/faceparser") |
|
|
|
context = dict() |
|
|
|
|
|
def gfpgan_face(image): |
|
return clientGFPGAN.predict(image, "v1.4", "2", api_name="/predict")[1] |
|
|
|
|
|
def enhance_face(image, upsampler, face_enhancer, scale): |
|
return clientSuperface.predict(image, upsampler, face_enhancer, scale, api_name="/predict") |
|
|
|
|
|
def zero_scratches(image): |
|
return clientZeroScratches.predict(image, api_name="/predict") |
|
|
|
|
|
def colorize_photo(image): |
|
return clientDeoldify.predict(image, api_name="/predict") |
|
|
|
|
|
def enhance_light(image): |
|
return clientEnhanceLight.predict(image, api_name="/predict") |
|
|
|
|
|
def zero_background(image, new_bgr=None): |
|
return clientZeroBackground.predict(image, new_bgr, api_name="/predict") |
|
|
|
|
|
def parse_face(image): |
|
return clientFaceParser.predict(image, api_name="/predict") |
|
|
|
|
|
def mirror(x): |
|
return x |
|
|
|
|
|
footer = r""" |
|
<center> |
|
<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> |
|
</br> |
|
<a href="https://www.buymeacoffee.com/leonelhs"> |
|
<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" /> |
|
</a> |
|
</center> |
|
</br> |
|
<center><span>[email protected]</span></center> |
|
""" |
|
|
|
with gr.Blocks() as app: |
|
gr.Request() |
|
|
|
with gr.Row(): |
|
gr.HTML("<center><h1>Face Shine</h1></center>") |
|
|
|
with gr.Tab("Photo restorer"): |
|
with gr.Row(): |
|
with gr.Column(scale=1): |
|
btn_hires = gr.Button(value="Enhance resolution") |
|
btn_eraser = gr.Button(value="Erase scratches") |
|
btn_color = gr.Button(value="Colorize photo") |
|
btn_light = gr.Button(value="Enhance light") |
|
btn_reset = gr.Button(value="Clear", variant="primary") |
|
|
|
with gr.Column(scale=4): |
|
with gr.Row(): |
|
img_input = gr.Image(label="Input", type="filepath") |
|
img_output = gr.Image(label="Result", type="filepath", interactive=False) |
|
|
|
with gr.Row(): |
|
btn_swap = gr.Button(value="Swap images") |
|
|
|
with gr.Tab("Background") as tab_background: |
|
with gr.Row(): |
|
with gr.Column(scale=1): |
|
btn_clear = gr.Button(value="Clear background") |
|
with gr.Accordion("New background", open=True): |
|
btn_newbgr = gr.Button(value="Change background") |
|
img_newbgr = gr.Image(label="Choose file for new background", type="filepath") |
|
with gr.Column(scale=4): |
|
with gr.Row(): |
|
img_input_bgr = gr.Image(label="Input", type="filepath") |
|
img_output_bgr = gr.Image(label="Result", type="filepath", interactive=False) |
|
|
|
with gr.Tab("Settings"): |
|
with gr.Accordion("Image restoration settings", open=False): |
|
restorer = gr.Dropdown([ |
|
'RealESRGAN_x2plus', |
|
'RealESRGAN_x4plus', |
|
'RealESRNet_x4plus', |
|
'AI-Forever_x2plus', |
|
'AI-Forever_x4plus', |
|
'RealESRGAN_x4plus_anime_6B', |
|
'realesr-animevideov3', |
|
'realesr-general-x4v3'], |
|
type="value", value='RealESRGAN_x4plus', label='General restoration algorithm', info="version") |
|
enhancer = gr.Dropdown([ |
|
'No additional face process', |
|
'GFPGANv1.2', |
|
'GFPGANv1.3', |
|
'GFPGANv1.4', |
|
'RestoreFormer'], |
|
type="value", value='No additional face process', label='Special face restoration algorithm', |
|
info="version") |
|
rescale = gr.Dropdown(["1", "2", "3", "4"], type="value", value="4", label="Rescaling factor") |
|
with gr.Accordion("Logs info", open=False): |
|
text_logger = gr.Textbox(label="login", lines=5, show_label=False) |
|
gr.Button("Save settings") |
|
|
|
btn_hires.click(enhance_face, inputs=[img_input, restorer, enhancer, rescale], |
|
outputs=[img_output, text_logger]) |
|
btn_eraser.click(zero_scratches, inputs=[img_input], outputs=[img_output]) |
|
btn_color.click(colorize_photo, inputs=[img_input], outputs=[img_output]) |
|
btn_light.click(enhance_light, inputs=[img_input], outputs=[img_output]) |
|
btn_clear.click(zero_background, inputs=[img_input_bgr], outputs=[img_output_bgr]) |
|
btn_newbgr.click(zero_background, inputs=[img_input_bgr, img_newbgr], outputs=[img_output_bgr]) |
|
btn_swap.click(mirror, inputs=[img_output], outputs=[img_input]) |
|
btn_reset.click(lambda: None, None, img_input, queue=False) |
|
tab_background.select(mirror, inputs=[img_input], outputs=[img_input_bgr]) |
|
|
|
with gr.Row(): |
|
gr.HTML(footer) |
|
|
|
app.launch(debug=True, enable_queue=True) |
|
|