Spaces:
Sleeping
Sleeping
import gradio as gr | |
import subprocess | |
def run_ultrasinger(opt_i, youtube_link, opt_o, mode, whisper_model, language, crepe_model, extra, device): | |
# Construct the command based on inputs | |
cmd = ["python", "UltraSinger.py"] | |
# Add input option | |
if opt_i: | |
cmd.extend(["-i", f'"{opt_i.name}"']) | |
elif youtube_link: | |
cmd.extend(["-i", f'"{youtube_link}"']) | |
else: | |
return "Error: No input file or YouTube link provided", "" | |
# Add output folder option | |
if opt_o: | |
cmd.extend(["-o", f'"{opt_o}"']) | |
# Add mode | |
if mode != "default": | |
mode_flags = { | |
"Create Ultrastar txt file": "-u", | |
"Create MIDI file": "-m", | |
"Create sheet file": "-s" | |
} | |
cmd.append(mode_flags[mode]) | |
# Add transcription options | |
if whisper_model: | |
cmd.extend(["--whisper", whisper_model]) | |
if language: | |
language_codes = { | |
"English": "en", "French": "fr", "German": "de", "Spanish": "es", | |
"Italian": "it", "Japanese": "ja", "Chinese": "zh", "Dutch": "nl", | |
"Ukrainian": "uk", "Portuguese": "pt" | |
} | |
cmd.extend(["--language", language_codes[language]]) | |
# Add pitcher options | |
cmd.extend(["--crepe", crepe_model]) | |
# Add extra options | |
if extra: | |
cmd.extend(extra.split()) | |
# Add device options | |
if device: | |
cmd.extend(device.split()) | |
# Debug: Print the command to check if it's constructed correctly | |
print("Running command:", ' '.join(cmd)) | |
# Execute the command | |
try: | |
result = subprocess.run(cmd, capture_output=True, text=True) | |
return result.stdout, result.stderr | |
except Exception as e: | |
return str(e), "Error occurred during execution" | |
def load_text_file(file_path): | |
try: | |
with open(file_path, 'r') as file: | |
return file.read() | |
except Exception as e: | |
return str(e) | |
# Define Gradio inputs and outputs for UltraSinger | |
opt_i = gr.File(label="Ultrastar.txt or audio file (.mp3, .wav)") | |
youtube_link = gr.Textbox(label="YouTube Link", placeholder="Enter YouTube URL here") | |
opt_o = gr.Textbox(label="Output folder") | |
mode = gr.Radio( | |
label="Mode options", | |
choices=[ | |
"default", "Create Ultrastar txt file", "Create MIDI file", | |
"Create sheet file" | |
], | |
value="default" | |
) | |
whisper_model = gr.Dropdown( | |
label="Whisper Model", | |
choices=[ | |
"tiny", "base", "small", "medium", "large-v1", "large-v2", | |
"tiny.en", "base.en", "small.en", "medium.en" | |
], | |
value="large-v2" | |
) | |
language = gr.Dropdown( | |
label="Language", | |
choices=[ | |
"English", "French", "German", "Spanish", "Italian", | |
"Japanese", "Chinese", "Dutch", "Ukrainian", "Portuguese" | |
], | |
value="English" | |
) | |
crepe_model = gr.Radio( | |
label="Crepe Model", | |
choices=["full", "tiny"], | |
value="full" | |
) | |
extra = gr.Textbox(label="Extra options (e.g., --hyphenation True)") | |
device = gr.Dropdown( | |
label="Device options", | |
choices=[ | |
"", "--force_cpu True", "--force_cpu False", | |
"--force_whisper_cpu True", "--force_whisper_cpu False", | |
"--force_crepe_cpu True", "--force_crepe_cpu False" | |
], | |
value="" | |
) | |
output_text = gr.Textbox(label="Standard Output") | |
error_text = gr.Textbox(label="Error Output") | |
# Define Gradio interface for UltraSinger | |
ultrasinger_tab = gr.Interface( | |
fn=run_ultrasinger, | |
inputs=[opt_i, youtube_link, opt_o, mode, whisper_model, language, crepe_model, extra, device], | |
outputs=[output_text, error_text], | |
title="UltraSinger UI", | |
description="Upload an Ultrastar.txt or an audio file, set the options, and run UltraSinger." | |
) | |
# Load content for Tab 1 and Tab 2 | |
tab1_content = load_text_file("info.txt") | |
tab2_content = load_text_file("usdb.txt") | |
# Create Gradio tabs | |
with gr.Blocks(theme="soft") as demo: | |
with gr.Tabs(): | |
with gr.TabItem("UltraSinger"): | |
ultrasinger_tab.render() | |
with gr.TabItem("Info"): | |
gr.Markdown(tab1_content) | |
with gr.TabItem("FOR USDB USERS"): | |
gr.Markdown(tab2_content) | |
# Launch the app | |
if __name__ == "__main__": | |
demo.launch() |