Files
Voice-Cloning-App/main.py

59 lines
1.8 KiB
Python
Raw Normal View History

2021-03-10 15:56:40 +00:00
import os
2021-05-01 15:49:25 +01:00
import sys
import shutil
2021-03-10 15:56:40 +00:00
import webbrowser
2021-06-04 22:53:03 +01:00
from engineio.async_drivers import threading # noqa
2021-03-10 15:56:40 +00:00
from flask_socketio import SocketIO
from flask import Flask
2021-03-18 16:54:52 +00:00
from application.check_ffmpeg import check_ffmpeg
2021-03-10 15:56:40 +00:00
2021-12-08 21:47:51 +00:00
FOLDERS = ["datasets", "models", "hifigan", "results", "languages", "training", "hifigan_training"]
def get_app_path():
if getattr(sys, "frozen", False):
return os.path.dirname(sys.executable)
return os.path.dirname(__file__)
2021-03-10 15:56:40 +00:00
def load_paths():
2021-12-08 21:47:51 +00:00
base_dir = get_app_path()
data_folder = os.path.join(base_dir, "data")
print("Loading data from", data_folder)
paths = {folder: os.path.join(data_folder, folder) for folder in FOLDERS}
2021-03-10 15:56:40 +00:00
for path in paths.values():
os.makedirs(path, exist_ok=True)
return paths
2021-05-01 15:49:25 +01:00
def cleanup_mei():
"""
Rudimentary workaround for https://github.com/pyinstaller/pyinstaller/issues/2379
"""
2021-09-15 14:23:15 +01:00
mei_bundle = getattr(sys, "_MEIPASS", None)
2021-05-01 15:49:25 +01:00
if mei_bundle:
dir_mei, current_mei = mei_bundle.split("_MEI")
for file in os.listdir(dir_mei):
if file.startswith("_MEI") and not file.endswith(current_mei):
try:
shutil.rmtree(os.path.join(dir_mei, file))
except PermissionError: # mainly to allow simultaneous pyinstaller instances
pass
2021-03-10 15:56:40 +00:00
paths = load_paths()
2021-03-18 12:27:38 +00:00
static = os.path.join("application", "static")
app = Flask(__name__, template_folder=static, static_folder=static)
2021-09-18 16:33:43 +01:00
app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 0
2021-03-10 15:56:40 +00:00
socketio = SocketIO(app, async_mode="threading", logger=True, engineio_logger=True, debug=True)
2021-06-04 22:53:03 +01:00
from application.views import * # noqa
2021-03-10 15:56:40 +00:00
if __name__ == "__main__":
2021-05-01 15:49:25 +01:00
cleanup_mei()
2021-03-18 16:53:04 +00:00
check_ffmpeg()
2021-03-10 15:56:40 +00:00
webbrowser.open_new_tab("http://localhost:5000")
2021-10-16 19:43:27 +01:00
socketio.run(app, host="0.0.0.0")