jhj0517 commited on
Commit
6736291
·
1 Parent(s): 94598d0

Apply gradio-i18n

Browse files
Files changed (2) hide show
  1. app.py +46 -42
  2. modules/utils/paths.py +1 -0
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import gradio as gr
 
2
 
3
  from modules.live_portrait.live_portrait_inferencer import LivePortraitInferencer
 
4
 
5
 
6
  class App:
@@ -8,62 +10,64 @@ class App:
8
  args=None):
9
  self.args = args
10
  self.app = gr.Blocks()
 
11
  self.inferencer = LivePortraitInferencer()
12
 
13
  @staticmethod
14
  def create_parameters():
15
  return [
16
- gr.Slider(label="Rotate Pitch", minimum=-20, maximum=20, step=0.5, value=0),
17
- gr.Slider(label="Rotate Yaw", minimum=-20, maximum=20, step=0.5, value=0),
18
- gr.Slider(label="Rotate Roll", minimum=-20, maximum=20, step=0.5, value=0),
19
- gr.Slider(label="Blink", minimum=-20, maximum=20, step=0.5, value=0),
20
- gr.Slider(label="Eyebrow", minimum=-20, maximum=20, step=0.5, value=0),
21
- gr.Slider(label="Wink", minimum=0, maximum=25, step=0.5, value=0),
22
- gr.Slider(label="Pupil X", minimum=-20, maximum=20, step=0.5, value=0),
23
- gr.Slider(label="Pupil Y", minimum=-20, maximum=20, step=0.5, value=0),
24
- gr.Slider(label="AAA", minimum=-30, maximum=120, step=1, value=0),
25
- gr.Slider(label="EEE", minimum=-20, maximum=20, step=0.2, value=0),
26
- gr.Slider(label="WOO", minimum=-20, maximum=20, step=0.2, value=0),
27
- gr.Slider(label="Smile", minimum=-2.0, maximum=2.0, step=0.01, value=0),
28
- gr.Slider(label="Source Ratio", minimum=0, maximum=1, step=0.01, value=1),
29
- gr.Slider(label="Sample Ratio", minimum=-0.2, maximum=1.2, step=0.01, value=1),
30
- gr.Dropdown(label="Sample Parts",
31
  choices=["OnlyExpression", "OnlyRotation", "OnlyMouth", "OnlyEyes", "All"], value="All"),
32
- gr.Slider(label="Crop Factor", minimum=1.5, maximum=2.5, step=0.1, value=1.7)
33
  ]
34
 
35
  def launch(self):
36
  with self.app:
37
- with gr.Row():
38
- with gr.Column():
39
- img_ref = gr.Image(label="Reference Image")
40
- with gr.Row():
41
- btn_gen = gr.Button("GENERATE", visible=False)
42
- with gr.Row():
43
- with gr.Column(scale=8):
44
- img_out = gr.Image(label="Output Image")
45
- with gr.Column(scale=2):
46
- expression_parameters = self.create_parameters()
47
- with gr.Accordion("Opt in features", visible=False):
48
- img_sample = gr.Image()
49
- img_motion_link = gr.Image()
50
- tb_exp = gr.Textbox()
 
51
 
52
- params = expression_parameters + [img_ref]
53
- opt_in_features_params = [img_sample, img_motion_link, tb_exp]
54
 
55
- gr.on(
56
- triggers=[param.change for param in params],
57
- fn=self.inferencer.edit_expression,
58
- inputs=params + opt_in_features_params,
59
- outputs=img_out
60
- )
61
 
62
- btn_gen.click(self.inferencer.edit_expression,
63
- inputs=params + opt_in_features_params,
64
- outputs=img_out)
65
 
66
- self.app.launch(inbrowser=True)
67
 
68
 
69
  app = App()
 
1
  import gradio as gr
2
+ from gradio_i18n import Translate, gettext as _
3
 
4
  from modules.live_portrait.live_portrait_inferencer import LivePortraitInferencer
5
+ from modules.utils.paths import *
6
 
7
 
8
  class App:
 
10
  args=None):
11
  self.args = args
12
  self.app = gr.Blocks()
13
+ self.i18n = Translate(I18N_YAML_PATH)
14
  self.inferencer = LivePortraitInferencer()
15
 
16
  @staticmethod
17
  def create_parameters():
18
  return [
19
+ gr.Slider(label=_("Rotate Pitch"), minimum=-20, maximum=20, step=0.5, value=0),
20
+ gr.Slider(label=_("Rotate Yaw"), minimum=-20, maximum=20, step=0.5, value=0),
21
+ gr.Slider(label=_("Rotate Roll"), minimum=-20, maximum=20, step=0.5, value=0),
22
+ gr.Slider(label=_("Blink"), minimum=-20, maximum=20, step=0.5, value=0),
23
+ gr.Slider(label=_("Eyebrow"), minimum=-20, maximum=20, step=0.5, value=0),
24
+ gr.Slider(label=_("Wink"), minimum=0, maximum=25, step=0.5, value=0),
25
+ gr.Slider(label=_("Pupil X"), minimum=-20, maximum=20, step=0.5, value=0),
26
+ gr.Slider(label=_("Pupil Y"), minimum=-20, maximum=20, step=0.5, value=0),
27
+ gr.Slider(label=_("AAA"), minimum=-30, maximum=120, step=1, value=0),
28
+ gr.Slider(label=_("EEE"), minimum=-20, maximum=20, step=0.2, value=0),
29
+ gr.Slider(label=_("WOO"), minimum=-20, maximum=20, step=0.2, value=0),
30
+ gr.Slider(label=_("Smile"), minimum=-2.0, maximum=2.0, step=0.01, value=0),
31
+ gr.Slider(label=_("Source Ratio"), minimum=0, maximum=1, step=0.01, value=1),
32
+ gr.Slider(label=_("Sample Ratio"), minimum=-0.2, maximum=1.2, step=0.01, value=1),
33
+ gr.Dropdown(label=_("Sample Parts"),
34
  choices=["OnlyExpression", "OnlyRotation", "OnlyMouth", "OnlyEyes", "All"], value="All"),
35
+ gr.Slider(label=_("Crop Factor"), minimum=1.5, maximum=2.5, step=0.1, value=1.7)
36
  ]
37
 
38
  def launch(self):
39
  with self.app:
40
+ with self.i18n:
41
+ with gr.Row():
42
+ with gr.Column():
43
+ img_ref = gr.Image(label=_("Reference Image"))
44
+ with gr.Row():
45
+ btn_gen = gr.Button("GENERATE", visible=False)
46
+ with gr.Row():
47
+ with gr.Column(scale=8):
48
+ img_out = gr.Image(label=_("Output Image"))
49
+ with gr.Column(scale=2):
50
+ expression_parameters = self.create_parameters()
51
+ with gr.Accordion("Opt in features", visible=False):
52
+ img_sample = gr.Image()
53
+ img_motion_link = gr.Image()
54
+ tb_exp = gr.Textbox()
55
 
56
+ params = expression_parameters + [img_ref]
57
+ opt_in_features_params = [img_sample, img_motion_link, tb_exp]
58
 
59
+ gr.on(
60
+ triggers=[param.change for param in params],
61
+ fn=self.inferencer.edit_expression,
62
+ inputs=params + opt_in_features_params,
63
+ outputs=img_out
64
+ )
65
 
66
+ btn_gen.click(self.inferencer.edit_expression,
67
+ inputs=params + opt_in_features_params,
68
+ outputs=img_out)
69
 
70
+ self.app.launch(inbrowser=True)
71
 
72
 
73
  app = App()
modules/utils/paths.py CHANGED
@@ -17,6 +17,7 @@ MODEL_PATHS = {
17
  "face_yolov8n": os.path.join(MODELS_DIR, "face_yolov8n.pt")
18
  }
19
  MASK_TEMPLATES = os.path.join(PROJECT_ROOT_DIR, "modules", "utils", "resources", "mask_template.png")
 
20
 
21
 
22
  def get_auto_incremental_file_path(dir_path: str, extension: str, prefix: str = ""):
 
17
  "face_yolov8n": os.path.join(MODELS_DIR, "face_yolov8n.pt")
18
  }
19
  MASK_TEMPLATES = os.path.join(PROJECT_ROOT_DIR, "modules", "utils", "resources", "mask_template.png")
20
+ I18N_YAML_PATH = os.path.join(PROJECT_ROOT_DIR, "i18n", "translation.yaml")
21
 
22
 
23
  def get_auto_incremental_file_path(dir_path: str, extension: str, prefix: str = ""):