jhj0517
commited on
Commit
·
3f75a4f
1
Parent(s):
b2fcecf
Add arg parses
Browse files- app.py +30 -3
- modules/utils/helper.py +15 -1
app.py
CHANGED
@@ -1,8 +1,10 @@
|
|
|
|
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:
|
@@ -71,7 +73,15 @@ class App:
|
|
71 |
inputs=params + opt_in_features_params,
|
72 |
outputs=img_out)
|
73 |
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
@staticmethod
|
77 |
def open_folder(folder_path: str):
|
@@ -81,8 +91,25 @@ class App:
|
|
81 |
os.system(f"start {folder_path}")
|
82 |
|
83 |
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
|
88 |
|
|
|
1 |
+
import argparse
|
2 |
import gradio as gr
|
3 |
from gradio_i18n import Translate, gettext as _
|
4 |
|
5 |
from modules.live_portrait.live_portrait_inferencer import LivePortraitInferencer
|
6 |
from modules.utils.paths import *
|
7 |
+
from modules.utils.helper import str2bool
|
8 |
|
9 |
|
10 |
class App:
|
|
|
73 |
inputs=params + opt_in_features_params,
|
74 |
outputs=img_out)
|
75 |
|
76 |
+
gradio_launch_args = {
|
77 |
+
"inbrowser": self.args.inbrowser,
|
78 |
+
"share": self.args.share,
|
79 |
+
"server_name": self.args.server_name,
|
80 |
+
"server_port": self.args.server_port,
|
81 |
+
"root_path": self.args.root_path,
|
82 |
+
"auth": (self.args.username, self.args.password) if self.args.username and self.args.password else None,
|
83 |
+
}
|
84 |
+
self.app.queue().launch(**gradio_launch_args)
|
85 |
|
86 |
@staticmethod
|
87 |
def open_folder(folder_path: str):
|
|
|
91 |
os.system(f"start {folder_path}")
|
92 |
|
93 |
|
94 |
+
if __name__ == "__main__":
|
95 |
+
|
96 |
+
parser = argparse.ArgumentParser()
|
97 |
+
parser.add_argument('--share', type=str2bool, default=False, nargs='?', const=True, help='Gradio share value')
|
98 |
+
parser.add_argument('--inbrowser', type=str2bool, default=True, nargs='?', const=True,
|
99 |
+
help='Whether to automatically starts on the browser or not')
|
100 |
+
parser.add_argument('--server_name', type=str, default=None, help='Gradio server host')
|
101 |
+
parser.add_argument('--server_port', type=int, default=None, help='Gradio server port')
|
102 |
+
parser.add_argument('--root_path', type=str, default=None, help='Gradio root path')
|
103 |
+
parser.add_argument('--username', type=str, default=None, help='Gradio authentication username')
|
104 |
+
parser.add_argument('--password', type=str, default=None, help='Gradio authentication password')
|
105 |
+
parser.add_argument('--model_dir', type=str, default=MODELS_DIR,
|
106 |
+
help='Directory path of the LivePortrait models')
|
107 |
+
parser.add_argument('--output_dir', type=str, default=OUTPUTS_DIR,
|
108 |
+
help='Directory path of the outputs')
|
109 |
+
_args = parser.parse_args()
|
110 |
+
|
111 |
+
app = App(args=_args)
|
112 |
+
app.launch()
|
113 |
|
114 |
|
115 |
|
modules/utils/helper.py
CHANGED
@@ -9,6 +9,8 @@ import os.path as osp
|
|
9 |
import cv2
|
10 |
import torch
|
11 |
import yaml
|
|
|
|
|
12 |
from rich.console import Console
|
13 |
from collections import OrderedDict
|
14 |
|
@@ -126,6 +128,18 @@ def resize_to_limit(img, max_dim=1280, n=2):
|
|
126 |
|
127 |
|
128 |
def load_yaml(file_path):
|
129 |
-
|
|
|
130 |
data = yaml.safe_load(file)
|
131 |
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
import cv2
|
10 |
import torch
|
11 |
import yaml
|
12 |
+
import argparse
|
13 |
+
import locale
|
14 |
from rich.console import Console
|
15 |
from collections import OrderedDict
|
16 |
|
|
|
128 |
|
129 |
|
130 |
def load_yaml(file_path):
|
131 |
+
encoding = locale.getpreferredencoding(False)
|
132 |
+
with open(file_path, 'r', encoding=encoding) as file:
|
133 |
data = yaml.safe_load(file)
|
134 |
return data
|
135 |
+
|
136 |
+
|
137 |
+
def str2bool(v):
|
138 |
+
if isinstance(v, bool):
|
139 |
+
return v
|
140 |
+
if v.lower() in ('yes', 'true', 't', 'y', '1'):
|
141 |
+
return True
|
142 |
+
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
|
143 |
+
return False
|
144 |
+
else:
|
145 |
+
raise argparse.ArgumentTypeError('Boolean value expected.')
|