add examples
Browse files- .gitignore +4 -0
- app.py +69 -48
- requirements.txt +1 -1
.gitignore
CHANGED
|
@@ -1 +1,5 @@
|
|
| 1 |
.idea/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
.idea/
|
| 2 |
+
backs/
|
| 3 |
+
gray/
|
| 4 |
+
lowres/
|
| 5 |
+
scratch/
|
app.py
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from gradio_client import Client
|
|
|
|
| 3 |
|
| 4 |
clientGFPGAN = Client("leonelhs/GFPGAN")
|
| 5 |
clientSuperface = Client("leonelhs/superface")
|
|
@@ -9,7 +13,14 @@ clientEnhanceLight = Client("leonelhs/Zero-DCE")
|
|
| 9 |
clientZeroBackground = Client("leonelhs/ZeroBackground")
|
| 10 |
clientFaceParser = Client("leonelhs/faceparser")
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
def gfpgan_face(image):
|
|
@@ -44,6 +55,10 @@ def mirror(x):
|
|
| 44 |
return x
|
| 45 |
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
footer = r"""
|
| 48 |
<center>
|
| 49 |
<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>
|
|
@@ -56,55 +71,61 @@ footer = r"""
|
|
| 56 |
<center><span>leonelhs@gmail.com</span></center>
|
| 57 |
"""
|
| 58 |
|
| 59 |
-
with gr.Blocks() as app:
|
| 60 |
-
gr.Request()
|
| 61 |
-
|
| 62 |
with gr.Row():
|
| 63 |
gr.HTML("<center><h1>Face Shine</h1></center>")
|
| 64 |
|
| 65 |
-
with gr.
|
| 66 |
-
with gr.
|
| 67 |
-
with gr.
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
with gr.
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
gr.
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
with gr.
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
btn_hires.click(enhance_face, inputs=[img_input, restorer, enhancer, rescale],
|
| 110 |
outputs=[img_output, text_logger])
|
|
@@ -117,4 +138,4 @@ with gr.Blocks() as app:
|
|
| 117 |
with gr.Row():
|
| 118 |
gr.HTML(footer)
|
| 119 |
|
| 120 |
-
app.launch(share=False, debug=True, enable_queue=True)
|
|
|
|
| 1 |
+
import zipfile
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
import gradio as gr
|
| 5 |
from gradio_client import Client
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
|
| 8 |
clientGFPGAN = Client("leonelhs/GFPGAN")
|
| 9 |
clientSuperface = Client("leonelhs/superface")
|
|
|
|
| 13 |
clientZeroBackground = Client("leonelhs/ZeroBackground")
|
| 14 |
clientFaceParser = Client("leonelhs/faceparser")
|
| 15 |
|
| 16 |
+
REPO_ID = "leonelhs/faceshine"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def download(file):
|
| 20 |
+
file_zip = hf_hub_download(repo_id=REPO_ID, filename=file + ".zip")
|
| 21 |
+
with zipfile.ZipFile(file_zip, "r") as zip_ref:
|
| 22 |
+
zip_ref.extractall(file)
|
| 23 |
+
return list(Path(file).iterdir())
|
| 24 |
|
| 25 |
|
| 26 |
def gfpgan_face(image):
|
|
|
|
| 55 |
return x
|
| 56 |
|
| 57 |
|
| 58 |
+
def active_first():
|
| 59 |
+
return gr.Tabs.update(selected=0)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
footer = r"""
|
| 63 |
<center>
|
| 64 |
<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>
|
|
|
|
| 71 |
<center><span>leonelhs@gmail.com</span></center>
|
| 72 |
"""
|
| 73 |
|
| 74 |
+
with gr.Blocks(title="Face Shine") as app:
|
|
|
|
|
|
|
| 75 |
with gr.Row():
|
| 76 |
gr.HTML("<center><h1>Face Shine</h1></center>")
|
| 77 |
|
| 78 |
+
with gr.Tabs() as tabs:
|
| 79 |
+
with gr.TabItem("Photo restorer", id=0):
|
| 80 |
+
with gr.Row():
|
| 81 |
+
with gr.Column(scale=1):
|
| 82 |
+
btn_hires = gr.Button(value="Enhance resolution")
|
| 83 |
+
btn_eraser = gr.Button(value="Erase scratches")
|
| 84 |
+
btn_color = gr.Button(value="Colorize photo")
|
| 85 |
+
btn_light = gr.Button(value="Enhance light")
|
| 86 |
+
with gr.Accordion("New background", open=False):
|
| 87 |
+
img_newbgr = gr.Image(label="Left empty for a transparent background", type="filepath")
|
| 88 |
+
btn_newbgr = gr.Button(value="Clear background")
|
| 89 |
+
|
| 90 |
+
with gr.Column(scale=4):
|
| 91 |
+
with gr.Row():
|
| 92 |
+
img_input = gr.Image(label="Input", type="filepath")
|
| 93 |
+
img_output = gr.Image(label="Result", type="filepath", interactive=False)
|
| 94 |
+
with gr.Row():
|
| 95 |
+
gr.ClearButton([img_input, img_output, img_newbgr], variant="stop")
|
| 96 |
+
btn_swap = gr.Button(value="Swap images", variant="primary")
|
| 97 |
+
|
| 98 |
+
with gr.TabItem("Examples", id=1):
|
| 99 |
+
gr.Examples(examples=download("lowres"), inputs=[img_input], label="Low resolution")
|
| 100 |
+
gr.Examples(examples=download("gray"), inputs=[img_input], label="Gray scale")
|
| 101 |
+
gr.Examples(examples=download("scratch"), inputs=[img_input], label="Scratched")
|
| 102 |
+
gr.Examples(examples=download("backs"), inputs=[img_newbgr], label="Backgrounds")
|
| 103 |
+
gr.Button(value="Ok", variant="primary").click(active_first, None, tabs)
|
| 104 |
+
|
| 105 |
+
with gr.TabItem("Settings", id=2):
|
| 106 |
+
with gr.Accordion("Image restoration settings", open=False):
|
| 107 |
+
restorer = gr.Dropdown([
|
| 108 |
+
'RealESRGAN_x2plus',
|
| 109 |
+
'RealESRGAN_x4plus',
|
| 110 |
+
'RealESRNet_x4plus',
|
| 111 |
+
'AI-Forever_x2plus',
|
| 112 |
+
'AI-Forever_x4plus',
|
| 113 |
+
'RealESRGAN_x4plus_anime_6B',
|
| 114 |
+
'realesr-animevideov3',
|
| 115 |
+
'realesr-general-x4v3'],
|
| 116 |
+
type="value", value='RealESRGAN_x4plus', label='General restoration algorithm', info="version")
|
| 117 |
+
enhancer = gr.Dropdown([
|
| 118 |
+
'No additional face process',
|
| 119 |
+
'GFPGANv1.2',
|
| 120 |
+
'GFPGANv1.3',
|
| 121 |
+
'GFPGANv1.4',
|
| 122 |
+
'RestoreFormer'],
|
| 123 |
+
type="value", value='No additional face process', label='Special face restoration algorithm',
|
| 124 |
+
info="version")
|
| 125 |
+
rescale = gr.Dropdown(["1", "2", "3", "4"], type="value", value="2", label="Rescaling factor")
|
| 126 |
+
with gr.Accordion("Logs info", open=False):
|
| 127 |
+
text_logger = gr.Textbox(label="login", lines=5, show_label=False)
|
| 128 |
+
gr.Button("Save settings")
|
| 129 |
|
| 130 |
btn_hires.click(enhance_face, inputs=[img_input, restorer, enhancer, rescale],
|
| 131 |
outputs=[img_output, text_logger])
|
|
|
|
| 138 |
with gr.Row():
|
| 139 |
gr.HTML(footer)
|
| 140 |
|
| 141 |
+
app.launch(share=False, debug=True, enable_queue=True, show_error=True)
|
requirements.txt
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
gradio
|
|
|
|
| 1 |
+
gradio~=3.35.2
|