|
|
"""HuggingFace Spaces app to host the stem conditioned results overview.""" |
|
|
import os |
|
|
import subprocess |
|
|
import sys |
|
|
import gradio as gr |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
|
|
|
app_dir = Path(__file__).parent |
|
|
parent_dir = app_dir.parent |
|
|
PROJECT_ROOT = parent_dir if (parent_dir / "stem_cond_overview.html").exists() else app_dir |
|
|
|
|
|
|
|
|
HTML_FILE = PROJECT_ROOT / "stem_cond_overview.html" |
|
|
|
|
|
|
|
|
def download_audio_files(): |
|
|
"""Download audio files on startup.""" |
|
|
print("Checking if audio files need to be downloaded...") |
|
|
audio_dir = PROJECT_ROOT / "data" / "fullmix_mp3s" |
|
|
|
|
|
|
|
|
if audio_dir.exists() and len(list(audio_dir.glob("*.mp3"))) > 0: |
|
|
print(f"Found {len(list(audio_dir.glob('*.mp3')))} existing audio files.") |
|
|
return |
|
|
|
|
|
print("No audio files found. Starting download...") |
|
|
try: |
|
|
|
|
|
script_path = Path(__file__).parent / "download_audio.py" |
|
|
result = subprocess.run( |
|
|
[sys.executable, str(script_path)], |
|
|
capture_output=True, |
|
|
text=True, |
|
|
timeout=3600 |
|
|
) |
|
|
print("Download script output:") |
|
|
print(result.stdout) |
|
|
if result.stderr: |
|
|
print("Download script errors:") |
|
|
print(result.stderr) |
|
|
except subprocess.TimeoutExpired: |
|
|
print("Download script timed out after 1 hour") |
|
|
except Exception as e: |
|
|
print(f"Error running download script: {e}") |
|
|
|
|
|
|
|
|
def render_html(): |
|
|
"""Load and return the HTML content.""" |
|
|
if HTML_FILE.exists(): |
|
|
with open(HTML_FILE, 'r', encoding='utf-8') as f: |
|
|
return f.read() |
|
|
return "<h1>HTML file not found</h1><p>Please generate the overview first.</p>" |
|
|
|
|
|
|
|
|
|
|
|
def create_interface(): |
|
|
"""Create the Gradio interface.""" |
|
|
html_content = render_html() |
|
|
|
|
|
|
|
|
demo = gr.HTML( |
|
|
value=html_content, |
|
|
label="Stem Conditioned Results Overview" |
|
|
) |
|
|
|
|
|
return demo |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
|
download_audio_files() |
|
|
|
|
|
|
|
|
demo = create_interface() |
|
|
demo.launch(server_name="0.0.0.0", server_port=7860) |
|
|
|
|
|
|