Download app_wrapper.py from alkasima/alkvoice: direct link, hf CLI and curl.
- Browser
- Download file 3.16 kB
-
https://huggingface.co/spaces/alkasima/alkvoice/resolve/main/app_wrapper.py
- Command line
-
hf download hf://spaces/alkasima/alkvoice/app_wrapper.py
-
curl -L -o app_wrapper.py https://huggingface.co/spaces/alkasima/alkvoice/resolve/main/app_wrapper.py
3.16 kB
| 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 | |