Fix PyInstaller crash with swagger ui page
This commit is contained in:
parent
a5ee90b44e
commit
3ccf2c7ab3
5 changed files with 31 additions and 7 deletions
|
|
@ -102,7 +102,7 @@ RUN .venv/bin/pyinstaller \
|
|||
--collect-data "gruut_lang_sw" \
|
||||
--collect-data 'espeak_phonemizer' \
|
||||
--collect-data 'phonemes2ids' \
|
||||
--hidden-import 'swagger-ui-py' \
|
||||
--hidden-import 'swagger_ui' \
|
||||
--collect-data 'mimic3_tts' \
|
||||
--collect-data 'mimic3_http' \
|
||||
pyinstaller/mimic3_server.py
|
||||
|
|
|
|||
|
|
@ -176,10 +176,12 @@ def get_app(args: argparse.Namespace, mimic3: Mimic3TextToSpeechSystem, temp_dir
|
|||
"""CSS static endpoint."""
|
||||
return await send_from_directory(_CSS_DIR, filename)
|
||||
|
||||
show_openapi = True
|
||||
|
||||
@app.route("/")
|
||||
async def app_index():
|
||||
"""Main page."""
|
||||
return await render_template("index.html")
|
||||
return await render_template("index.html", show_openapi=show_openapi)
|
||||
|
||||
@app.route("/api/tts", methods=["GET", "POST"])
|
||||
async def app_tts() -> Response:
|
||||
|
|
@ -275,9 +277,17 @@ def get_app(args: argparse.Namespace, mimic3: Mimic3TextToSpeechSystem, temp_dir
|
|||
return Response(wav_bytes, mimetype="audio/wav")
|
||||
|
||||
# Swagger UI
|
||||
api_doc(
|
||||
app, config_path=_DIR / "swagger.yaml", url_prefix="/openapi", title="Mimic 3"
|
||||
)
|
||||
try:
|
||||
api_doc(
|
||||
app,
|
||||
config_path=_DIR / "swagger.yaml",
|
||||
url_prefix="/openapi",
|
||||
title="Mimic 3",
|
||||
)
|
||||
except Exception:
|
||||
# Fails with PyInstaller for some reason
|
||||
_LOGGER.exception("Error setting up swagger UI page")
|
||||
show_openapi = False
|
||||
|
||||
@app.errorhandler(Exception)
|
||||
async def handle_error(err) -> typing.Tuple[str, int]:
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ def get_args() -> argparse.Namespace:
|
|||
parser.add_argument(
|
||||
"--debug", action="store_true", help="Print DEBUG messages to console"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--server", action="store_true", help="Dummy argument from PyInstaller script"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--version", action="store_true", help="Print version to console and exit"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -54,8 +54,11 @@
|
|||
</div>
|
||||
<div class="col-auto">
|
||||
<button id="speak-button" name="speak" class="btn btn-lg btn-primary" alt="Generate speech">Speak</button>
|
||||
|
||||
{% if show_openapi %}
|
||||
<br/><br />
|
||||
<a href="/openapi/" title="OpenAPI page" target="_blank" class="badge badge-info">API</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
|
|
|
|||
|
|
@ -15,7 +15,15 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""Stub for PyInstaller"""
|
||||
import sys
|
||||
|
||||
from mimic3_tts.__main__ import main
|
||||
|
||||
main()
|
||||
if (len(sys.argv) > 1) and (sys.argv[1] == "--server"):
|
||||
from mimic3_http.__main__ import main as http_main
|
||||
|
||||
sys.argv = [sys.argv[0]] + sys.argv[2:]
|
||||
http_main()
|
||||
else:
|
||||
from mimic3_tts.__main__ import main as tts_main
|
||||
|
||||
tts_main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue