Spaces:
Running
Running
| import gradio as gr | |
| from fastapi import FastAPI | |
| from api.routes import router as voice_router | |
| import numpy as np | |
| # ----------------------------- | |
| # FastAPI core app | |
| # ----------------------------- | |
| app = FastAPI( | |
| title="Auralis Vocal Fatigue Scoring API", | |
| version="1.0" | |
| ) | |
| # Register API routes | |
| app.include_router( | |
| voice_router, | |
| prefix="/api/v1/voice", | |
| tags=["Vocal Fatigue Scoring"] | |
| ) | |
| def root(): | |
| return { | |
| "name": "Auralis Vocal Fatigue Scoring API", | |
| "status": "running", | |
| "api": "/api/v1/voice/score", | |
| "ui": "/" | |
| } | |
| def health(): | |
| return {"status": "ok"} | |
| # ----------------------------- | |
| # Gradio interface | |
| # ----------------------------- | |
| from audio.preprocessing import load_audio, extract_features | |
| from model.ecapa import ECAPAENCODER | |
| from model.scorer import fatigue_score_0_to_100 | |
| from core.config import LOW_PERCENTILE, HIGH_PERCENTILE, FATIGUE_AXIS, REF_C_H | |
| # Load once (IMPORTANT) | |
| encoder = ECAPAENCODER() | |
| C_h = np.load(REF_C_H) | |
| fatigue_axis = np.load(FATIGUE_AXIS) | |
| low = float(np.load(LOW_PERCENTILE)["arr_0"]) | |
| high = float(np.load(HIGH_PERCENTILE)["arr_0"]) | |
| def gradio_score(audio_path: str): | |
| """ | |
| Direct pipeline call (NO HTTP, NO API call) | |
| """ | |
| wav = load_audio(audio_path) | |
| _ = extract_features(wav) | |
| wav = wav.squeeze() | |
| emb = encoder.encode(wav) | |
| score = float( | |
| fatigue_score_0_to_100(emb, C_h, fatigue_axis, low, high) | |
| ) | |
| return score | |
| gradio_app = gr.Interface( | |
| fn=gradio_score, | |
| inputs=gr.Audio(type="filepath", label="Upload speech audio"), | |
| outputs=gr.Number(label="Vocal Fatigue Score (0β100)"), | |
| title="Auralis β Vocal Fatigue Scoring", | |
| description="Upload speech audio to obtain an objective vocal fatigue score." | |
| ) | |
| # π Mount Gradio onto FastAPI | |
| app = gr.mount_gradio_app(app, gradio_app, path="/") | |