Spaces:
Build error
Build error
File size: 887 Bytes
71f6464 db56cf5 71f6464 db56cf5 71f6464 1ba4a0c 71f6464 |
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 |
import pickle
from typing import Union
from fastapi import Request
import torch
from transformers import pipeline
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"status": "ok"}
TRANSCRIBE_PIPELINE = pipeline(
"automatic-speech-recognition",
model="openai/whisper-large-v3",
torch_dtype=torch.float16,
device="mps",
model_kwargs={"attn_implementation": "sdpa"},
)
@app.post("/transcribe")
async def transcribe(request: Request):
body = await request.body()
audio_chunk = pickle.loads(body)
outputs = TRANSCRIBE_PIPELINE.pipe(
audio_chunk,
chunk_length_s=30,
batch_size=24,
generate_kwargs={
'task': 'transcribe',
'language': 'english'
},
return_timestamps='word'
)
text = outputs["text"].strip()
return {"transcribe": text}
|