File size: 851 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
# Add this to api.py for optional API key protection

import os
from fastapi import FastAPI, File, UploadFile, Form, HTTPException, Header
from typing import Optional

# Get API key from environment variable (set in HF Space settings)
API_KEY = os.getenv("API_KEY", None)  # Set to None to disable auth

# Add this to your enhance endpoint
@app.post("/enhance")
async def enhance_audio_endpoint(
    file: UploadFile = File(...),
    speech_level: float = Form(80.0),
    background_level: float = Form(85.0),
    x_api_key: Optional[str] = Header(None)  # Add this line
):
    # Optional API key check
    if API_KEY and x_api_key != API_KEY:
        raise HTTPException(
            status_code=401, 
            detail="Invalid or missing API key. Add X-API-Key header."
        )
    
    # ... rest of your existing code