Spaces:
Runtime error
Runtime error
import gradio as gr | |
import sys | |
import os | |
import logging | |
from pathlib import Path # Added Path import | |
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 | |
# 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 | |
# Added file browser functionality | |
from datetime import datetime | |
DATA_PATH = Path("logs") | |
def get_storage(): | |
all_files = [] | |
total_usage = 0 | |
for file in DATA_PATH.glob("**/*"): | |
if file.is_file(): | |
# Get file metadata | |
stat = file.stat() | |
modified_time = datetime.fromtimestamp(stat.st_mtime).strftime("%Y-%m-%d %H:%M:%S") | |
created_time = datetime.fromtimestamp(stat.st_ctime).strftime("%Y-%m-%d %H:%M:%S") | |
all_files.append({ | |
"path": str(file.resolve()), | |
"name": file.name, | |
"size": f"{stat.st_size/1024**2:.2f} MB", | |
"modified": modified_time, | |
"created": created_time, | |
"relative_path": str(file.relative_to(DATA_PATH)) | |
}) | |
total_usage += stat.st_size | |
# Sort by modification date (newest first) | |
all_files.sort(key=lambda x: x['modified'], reverse=True) | |
return ( | |
[f["path"] for f in all_files], # For Files component | |
[[f["relative_path"], f["size"], f["modified"], f["created"]] for f in all_files], # For Dataframe | |
f"{total_usage / (1024 ** 3):.3f} GB" | |
) | |
def process_model_data(json_data): | |
try: | |
data = json.loads(json_data) | |
model_data = data.get("model_data", []) | |
for model in model_data: | |
if len(model) >= 3: | |
version, name, zip_url, *_ = model | |
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}") | |
json_data = '''{ | |
"model_data":[ | |
["v1", "ayaka-jp", "https://huggingface.co/ArkanDash/rvc-genshin-impact/resolve/main/prezipped/v1/ayaka-jp%20100%20epochs%2040k.zip", "https://static.wikia.nocookie.net/gensin-impact/images/d/d0/Character_Kamisato_Ayaka_Full_Wish.png"], | |
["v2", "Arlecchino-jp-v2", "https://huggingface.co/riezzz/rvc-models/resolve/main/arlecchino-pth-300.zip", "https://static.wikia.nocookie.net/gensin-impact/images/f/f8/Character_Arlecchino_Full_Wish.png"] | |
] | |
}''' | |
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")): | |
with gr.Row(): | |
with gr.Column(): | |
refresh_btn = gr.Button("π Refresh") | |
file_table = gr.Dataframe( | |
headers=["File Path", "Size", "Last Modified", "Created"], | |
datatype=["str", "str", "str", "str"], | |
interactive=False, | |
height=500 | |
) | |
with gr.Column(): | |
file_browser = gr.Files( | |
label="All Log Files", | |
file_count="multiple", | |
height=400 | |
) | |
storage_usage = gr.Text(label="Total Usage") | |
refresh_btn.click( | |
get_storage, | |
inputs=None, | |
outputs=[file_browser, file_table, storage_usage] | |
) | |
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, | |
allowed_paths=[str(DATA_PATH)] | |
) | |
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 |