Skip to content

Commit ab7d84b

Browse files
committed
refactor(server): address linter issues
1 parent 8503500 commit ab7d84b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

TTS/server/server.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!flask/bin/python
2+
3+
"""TTS demo server."""
4+
25
import argparse
36
import io
47
import json
@@ -13,7 +16,8 @@
1316
try:
1417
from flask import Flask, render_template, render_template_string, request, send_file
1518
except ImportError as e:
16-
raise ImportError("Server requires requires flask, use `pip install coqui-tts[server]`.") from e
19+
msg = "Server requires requires flask, use `pip install coqui-tts[server]`"
20+
raise ImportError(msg) from e
1721

1822
from TTS.config import load_config
1923
from TTS.utils.generic_utils import ConsoleFormatter, setup_logger
@@ -24,17 +28,11 @@
2428
setup_logger("TTS", level=logging.INFO, screen=True, formatter=ConsoleFormatter())
2529

2630

27-
def create_argparser():
28-
def convert_boolean(x):
29-
return x.lower() in ["true", "1", "yes"]
30-
31+
def create_argparser() -> argparse.ArgumentParser:
3132
parser = argparse.ArgumentParser()
3233
parser.add_argument(
3334
"--list_models",
34-
type=convert_boolean,
35-
nargs="?",
36-
const=True,
37-
default=False,
35+
action="store_true",
3836
help="list available pre-trained tts and vocoder models.",
3937
)
4038
parser.add_argument(
@@ -62,9 +60,13 @@ def convert_boolean(x):
6260
parser.add_argument("--vocoder_config_path", type=str, help="Path to vocoder model config file.", default=None)
6361
parser.add_argument("--speakers_file_path", type=str, help="JSON file for multi-speaker model.", default=None)
6462
parser.add_argument("--port", type=int, default=5002, help="port to listen on.")
65-
parser.add_argument("--use_cuda", type=convert_boolean, default=False, help="true to use CUDA.")
66-
parser.add_argument("--debug", type=convert_boolean, default=False, help="true to enable Flask debug mode.")
67-
parser.add_argument("--show_details", type=convert_boolean, default=False, help="Generate model detail page.")
63+
parser.add_argument("--use_cuda", action=argparse.BooleanOptionalAction, default=False, help="true to use CUDA.")
64+
parser.add_argument(
65+
"--debug", action=argparse.BooleanOptionalAction, default=False, help="true to enable Flask debug mode."
66+
)
67+
parser.add_argument(
68+
"--show_details", action=argparse.BooleanOptionalAction, default=False, help="Generate model detail page."
69+
)
6870
return parser
6971

7072

@@ -168,17 +170,15 @@ def index():
168170
def details():
169171
if args.config_path is not None and os.path.isfile(args.config_path):
170172
model_config = load_config(args.config_path)
171-
else:
172-
if args.model_name is not None:
173-
model_config = load_config(config_path)
173+
elif args.model_name is not None:
174+
model_config = load_config(config_path)
174175

175176
if args.vocoder_config_path is not None and os.path.isfile(args.vocoder_config_path):
176177
vocoder_config = load_config(args.vocoder_config_path)
178+
elif args.vocoder_name is not None:
179+
vocoder_config = load_config(vocoder_config_path)
177180
else:
178-
if args.vocoder_name is not None:
179-
vocoder_config = load_config(vocoder_config_path)
180-
else:
181-
vocoder_config = None
181+
vocoder_config = None
182182

183183
return render_template(
184184
"details.html",

0 commit comments

Comments
 (0)