import subprocess import sys # Start FastAPI backend in background print("๐Ÿš€ Starting AI Voice Enhancer API...") subprocess.Popen([sys.executable, "api.py"]) # Create minimal Gradio interface (required for Gradio SDK on HF Spaces) import gradio as gr # Info interface with gr.Blocks(title="AI Voice Enhancer API") as demo: gr.Markdown(""" # ๐ŸŽ™๏ธ AI Voice Enhancer API ## โœ… Backend API is Running This Space provides a REST API for audio enhancement. ### ๐Ÿ“ก Available Endpoints: - **GET** `/` - API information - **GET** `/health` - Health check - **POST** `/enhance` - Enhance audio file - **DELETE** `/cleanup` - Clean temporary files ### ๐Ÿ”ง How to Use: #### Option 1: Use the Frontend (Recommended) Download the frontend files from the repository and open `index.html`: 1. Enter this Space's URL in the API settings 2. Upload your audio file 3. Adjust enhancement levels 4. Click "Enhance Audio" #### Option 2: Direct API Call ```bash curl -X POST "https://YOUR-SPACE-NAME.hf.space/enhance" \\ -F "file=@input.wav" \\ -F "speech_level=80" \\ -F "background_level=85" \\ -o enhanced.wav ``` #### Option 3: Python ```python import requests url = "https://YOUR-SPACE-NAME.hf.space/enhance" files = {"file": open("input.wav", "rb")} data = {"speech_level": 80, "background_level": 85} response = requests.post(url, files=files, data=data) with open("enhanced.wav", "wb") as f: f.write(response.content) ``` ### ๐ŸŽš๏ธ Parameters: - **speech_level**: 0-100 (default: 80) - Voice clarity enhancement - **background_level**: 0-100 (default: 85) - Noise reduction strength ### ๐Ÿ“Š Supported Formats: WAV, MP3, M4A, FLAC, OGG, AAC ### โš™๏ธ Tech Stack: - FastAPI for REST API - Facebook Denoiser (DNS) for noise suppression - Multi-stage FFmpeg processing for clarity - EBU R128 loudness normalization --- **Note**: The FastAPI server is running in the background on port 7860. This Gradio interface is just for display purposes. """) gr.Markdown("### ๐Ÿงช Test the API") with gr.Row(): test_url = gr.Textbox( label="API Endpoint", value="/health", placeholder="/health" ) test_btn = gr.Button("Test Endpoint", variant="primary") test_output = gr.JSON(label="Response") def test_endpoint(endpoint): import requests try: url = f"http://localhost:7860{endpoint}" response = requests.get(url, timeout=5) return response.json() except Exception as e: return {"error": str(e)} test_btn.click(fn=test_endpoint, inputs=test_url, outputs=test_output) # Launch Gradio interface demo.launch(server_name="0.0.0.0", server_port=7861) # Different port from API