genshin.applio / app.py
soiz1's picture
Update app.py
3478739 verified
import gradio as gr
import sys
import os
import logging
DEFAULT_PORT = 7860
MAX_PORT_ATTEMPTS = 10
# Set up logging
logging.getLogger("uvicorn").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
# Add current directory to sys.path
now_dir = os.getcwd()
sys.path.append(now_dir)
# Zluda hijack
import rvc.lib.zluda
# Import Tabs
from tabs.inference.inference import inference_tab
from tabs.train.train import train_tab
from tabs.extra.extra import extra_tab
from tabs.report.report import report_tab
from tabs.download.download import download_tab
from tabs.tts.tts import tts_tab
from tabs.voice_blender.voice_blender import voice_blender_tab
from tabs.plugins.plugins import plugins_tab
from tabs.settings.settings import settings_tab
import json
# Run prerequisites
from core import run_prerequisites_script
run_prerequisites_script(
pretraineds_hifigan=True,
models=True,
exe=True,
)
# Initialize i18n
from assets.i18n.i18n import I18nAuto
i18n = I18nAuto()
# Start Discord presence if enabled
from tabs.settings.sections.presence import load_config_presence
if load_config_presence():
from assets.discord_presence import RPCManager
RPCManager.start_presence()
# Check installation
import assets.installation_checker as installation_checker
installation_checker.check_installation()
# Load theme
import assets.themes.loadThemes as loadThemes
my_applio = loadThemes.load_theme() or "ParityError/Interstellar"
#-------------------
import json
from rvc.lib.tools.model_download import model_download_pipeline
import urllib.parse
def process_model_data(json_data):
try:
# JSONデータをPythonの辞書型に変換
#data = json.loads(json_data)
# "model_data"キーにアクセス
model_data = json_data.get("model_data", [])
# 各モデルデータに対して処理を実行
for model in model_data:
if len(model) >= 3: # URLが存在するか確認
version, name, zip_url, *_ = model
# URLをデコードし、空白部分を「_」に置き換え
decoded_url = urllib.parse.unquote(zip_url)
normalized_zip_name = os.path.splitext(os.path.basename(decoded_url))[0].replace(" ", "_")
pth_path = f"logs/{normalized_zip_name}/{normalized_zip_name}.pth"
# ファイルが存在する場合はスキップ
if os.path.exists(pth_path):
print(f"{pth_path} は既に存在します。スキップします。")
continue
# ファイルが存在しない場合は処理を実行
print(f"{pth_path} が存在しません。処理を開始します。")
model_download_pipeline(zip_url)
except json.JSONDecodeError as e:
print(f"JSON解析エラー: {e}")
import requests
def fetch_json_data():
url = "https://huggingface.co/datasets/public-soiz1/genshin-applio-rvc-data/raw/main/data.json"
response = requests.get(url)
if response.status_code == 200:
try:
json_data = response.json() # JSONとしてパース
return json_data
except json.JSONDecodeError:
print("JSONデコードエラー: 正しいJSON形式ではありません。")
return None
else:
print(f"エラー: ステータスコード {response.status_code}")
return None
# 関数を呼び出してデータを取得
json_data = fetch_json_data()
process_model_data(json_data)
#----------
# Define Gradio interface
with gr.Blocks(
theme=my_applio, title="Applio", css="footer{display:none !important}"
) as Applio:
gr.Markdown("# Applio")
gr.Markdown(
i18n(
"A simple, high-quality voice conversion tool focused on ease of use and performance."
)
)
gr.Markdown(
i18n(
"[Support](https://discord.gg/urxFjYmYYh) — [GitHub](https://github.com/IAHispano/Applio)"
)
)
with gr.Tab(i18n("Inference")):
inference_tab()
with gr.Tab(i18n("Training")):
train_tab()
with gr.Tab(i18n("TTS")):
tts_tab()
with gr.Tab(i18n("Voice Blender")):
voice_blender_tab()
with gr.Tab(i18n("Plugins")):
plugins_tab()
with gr.Tab(i18n("Download")):
download_tab()
with gr.Tab(i18n("Report a Bug")):
report_tab()
with gr.Tab(i18n("Extra")):
extra_tab()
with gr.Tab(i18n("Settings")):
settings_tab()
gr.Markdown(
"""
<div style="text-align: center; font-size: 0.9em; text-color: a3a3a3;">
By using Applio, you agree to comply with ethical and legal standards, respect intellectual property and privacy rights, avoid harmful or prohibited uses, and accept full responsibility for any outcomes, while Applio disclaims liability and reserves the right to amend these terms.
</div>
"""
)
def launch_gradio(port):
Applio.launch(
favicon_path="assets/ICON.ico",
share="--share" in sys.argv,
inbrowser="--open" in sys.argv,
server_port=port,
)
def get_port_from_args():
if "--port" in sys.argv:
port_index = sys.argv.index("--port") + 1
if port_index < len(sys.argv):
return int(sys.argv[port_index])
return DEFAULT_PORT
if __name__ == "__main__":
port = get_port_from_args()
for _ in range(MAX_PORT_ATTEMPTS):
try:
launch_gradio(port)
break
except OSError:
print(
f"Failed to launch on port {port}, trying again on port {port - 1}..."
)
port -= 1
except Exception as error:
print(f"An error occurred launching Gradio: {error}")
break