"""HuggingFace Spaces app to host the stem conditioned results overview.""" import os import subprocess import sys import gradio as gr from pathlib import Path # Determine project root (works whether app.py is in root or subdirectory) # Try parent.parent first (if in huggingface/), then just parent (if in root) 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 # Path to the HTML file 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" # Check if download is needed 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: # Run the download script script_path = Path(__file__).parent / "download_audio.py" result = subprocess.run( [sys.executable, str(script_path)], capture_output=True, text=True, timeout=3600 # 1 hour timeout ) 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 "

HTML file not found

Please generate the overview first.

" # Create Gradio interface def create_interface(): """Create the Gradio interface.""" html_content = render_html() # Create a Gradio HTML component demo = gr.HTML( value=html_content, label="Stem Conditioned Results Overview" ) return demo if __name__ == "__main__": # Download audio files on startup download_audio_files() # Launch the interface demo = create_interface() demo.launch(server_name="0.0.0.0", server_port=7860)