leonelhs commited on
Commit
3b731e7
·
1 Parent(s): eb90f17

GFPGAN Xintao

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -5,7 +5,7 @@ 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")
10
  clientZeroScratches = Client("leonelhs/ZeroScratches")
11
  clientDeoldify = Client("leonelhs/deoldify")
@@ -23,8 +23,8 @@ def download(file):
23
  return list(Path(file).iterdir())
24
 
25
 
26
- def gfpgan_face(image):
27
- return clientGFPGAN.predict(image, "v1.4", "2", api_name="/predict")[1]
28
 
29
 
30
  def enhance_face(image, upsampler, face_enhancer, scale):
@@ -45,7 +45,7 @@ def enhance_light(image):
45
 
46
  def zero_background(image, new_bgr=None):
47
  # return clientZeroBackground.predict(image, new_bgr, api_name="/predict")[0]
48
- # Fixme: cant find predict funciton by name
49
  return clientZeroBackground.predict(image, new_bgr, fn_index=0)[1]
50
 
51
 
@@ -81,7 +81,7 @@ with gr.Blocks(title="Face Shine") as app:
81
  with gr.TabItem("Photo restorer", id=0):
82
  with gr.Row():
83
  with gr.Column(scale=1):
84
- btn_hires = gr.Button(value="Enhance resolution")
85
  btn_eraser = gr.Button(value="Erase scratches")
86
  btn_color = gr.Button(value="Colorize photo")
87
  btn_light = gr.Button(value="Enhance light")
@@ -106,6 +106,13 @@ with gr.Blocks(title="Face Shine") as app:
106
 
107
  with gr.TabItem("Settings", id=2):
108
  with gr.Accordion("Image restoration settings", open=False):
 
 
 
 
 
 
 
109
  restorer = gr.Dropdown([
110
  'RealESRGAN_x2plus',
111
  'RealESRGAN_x4plus',
@@ -115,22 +122,15 @@ with gr.Blocks(title="Face Shine") as app:
115
  'RealESRGAN_x4plus_anime_6B',
116
  'realesr-animevideov3',
117
  'realesr-general-x4v3'],
118
- type="value", value='RealESRGAN_x4plus', label='General restoration algorithm', info="version")
119
- enhancer = gr.Dropdown([
120
- 'No additional face process',
121
- 'GFPGANv1.2',
122
- 'GFPGANv1.3',
123
- 'GFPGANv1.4',
124
- 'RestoreFormer'],
125
- type="value", value='No additional face process', label='Special face restoration algorithm',
126
- info="version")
127
  rescale = gr.Dropdown(["1", "2", "3", "4"], type="value", value="2", label="Rescaling factor")
128
  with gr.Accordion("Logs info", open=False):
129
  text_logger = gr.Textbox(label="login", lines=5, show_label=False)
130
  gr.Button("Save settings")
131
 
132
- btn_hires.click(enhance_face, inputs=[img_input, restorer, enhancer, rescale],
133
- outputs=[img_output, text_logger])
134
  btn_eraser.click(zero_scratches, inputs=[img_input], outputs=[img_output])
135
  btn_color.click(colorize_photo, inputs=[img_input], outputs=[img_output])
136
  btn_light.click(enhance_light, inputs=[img_input], outputs=[img_output])
 
5
  from gradio_client import Client
6
  from huggingface_hub import hf_hub_download
7
 
8
+ clientGFPGAN = Client("Xintao/GFPGAN")
9
  clientSuperface = Client("leonelhs/superface")
10
  clientZeroScratches = Client("leonelhs/ZeroScratches")
11
  clientDeoldify = Client("leonelhs/deoldify")
 
23
  return list(Path(file).iterdir())
24
 
25
 
26
+ def gfpgan_face(image, version, scale):
27
+ return clientGFPGAN.predict(image, version, scale, fn_index=0)[0]
28
 
29
 
30
  def enhance_face(image, upsampler, face_enhancer, scale):
 
45
 
46
  def zero_background(image, new_bgr=None):
47
  # return clientZeroBackground.predict(image, new_bgr, api_name="/predict")[0]
48
+ # Fixme: cant find predict function by name
49
  return clientZeroBackground.predict(image, new_bgr, fn_index=0)[1]
50
 
51
 
 
81
  with gr.TabItem("Photo restorer", id=0):
82
  with gr.Row():
83
  with gr.Column(scale=1):
84
+ btn_hires = gr.Button(value="Enhance faces")
85
  btn_eraser = gr.Button(value="Erase scratches")
86
  btn_color = gr.Button(value="Colorize photo")
87
  btn_light = gr.Button(value="Enhance light")
 
106
 
107
  with gr.TabItem("Settings", id=2):
108
  with gr.Accordion("Image restoration settings", open=False):
109
+ enhancer = gr.Dropdown([
110
+ 'v1.2',
111
+ 'v1.3',
112
+ 'v1.4',
113
+ 'RestoreFormer'],
114
+ type="value", value='RestoreFormer', label='GFPGAN face restoration algorithm',
115
+ info="version")
116
  restorer = gr.Dropdown([
117
  'RealESRGAN_x2plus',
118
  'RealESRGAN_x4plus',
 
122
  'RealESRGAN_x4plus_anime_6B',
123
  'realesr-animevideov3',
124
  'realesr-general-x4v3'],
125
+ type="value", value='RealESRGAN_x4plus',
126
+ label='Real-ESRGAN image restoration algorithm', info="version", visible=False)
 
 
 
 
 
 
 
127
  rescale = gr.Dropdown(["1", "2", "3", "4"], type="value", value="2", label="Rescaling factor")
128
  with gr.Accordion("Logs info", open=False):
129
  text_logger = gr.Textbox(label="login", lines=5, show_label=False)
130
  gr.Button("Save settings")
131
 
132
+ # btn_hires.click(enhance_face, inputs=[img_input, restorer, enhancer, rescale], outputs=[img_output, text_logger])
133
+ btn_hires.click(gfpgan_face, inputs=[img_input, enhancer, rescale], outputs=[img_output])
134
  btn_eraser.click(zero_scratches, inputs=[img_input], outputs=[img_output])
135
  btn_color.click(colorize_photo, inputs=[img_input], outputs=[img_output])
136
  btn_light.click(enhance_light, inputs=[img_input], outputs=[img_output])