Spaces:
Runtime error
Runtime error
Download app.py from itapunjabi/server.py: direct link, hf CLI and curl.
- Browser
- Download file 857 Bytes
-
https://huggingface.co/spaces/itapunjabi/server.py/resolve/main/app.py
- Command line
-
hf download hf://spaces/itapunjabi/server.py/app.py
-
curl -L -o app.py https://huggingface.co/spaces/itapunjabi/server.py/resolve/main/app.py
857 Bytes
| from fastapi import FastAPI, UploadFile, File, Form | |
| from ai4bharat.indicstt import IndicSTT | |
| import numpy as np | |
| import wave, io | |
| app = FastAPI() | |
| # Carica il modello UNA VOLTA all'avvio | |
| print("⏳ Caricamento IndicConformer...") | |
| model = IndicSTT("ai4bharat/indic-conformer-600m-multilingual") | |
| print("✅ Modello pronto!") | |
| async def transcribe(audio: UploadFile = File(...), language: str = Form("pa")): | |
| contents = await audio.read() | |
| # Converti WAV → Float32 normalizzato | |
| with wave.open(io.BytesIO(contents), 'rb') as f: | |
| frames = f.readframes(f.getnframes()) | |
| samples = np.frombuffer(frames, dtype=np.int16).astype(np.float32) / 32768.0 | |
| # Trascrivi | |
| result = model.transcribe(samples, language=language) | |
| return {"transcript": result["transcript"], "provider": "indic-conformer"} |