File size: 3,159 Bytes
93f5fa9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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