Spaces:
Sleeping
Sleeping
from fastapi import APIRouter, File, UploadFile, Form | |
from huggingface_hub import InferenceClient | |
router = APIRouter() | |
# Add model and audio parameters to the function signature | |
async def automatic_speech_recognition( | |
model: str = Form(..., description="The model to use for ASR. Can be a model ID hosted on the Hugging Face Hub or a URL to a deployed Inference Endpoint. If not provided, the default recommended model for ASR will be used."), | |
audio: UploadFile = File(..., description="The content to transcribe. It can be raw audio bytes, local audio file, or a URL to an audio file.") | |
): | |
# Use the 'model' parameter from the form data | |
client = InferenceClient(model=model) | |
# Read the uploaded file content | |
audio_bytes = await audio.read() | |
# Pass the audio bytes to the client method | |
res = client.automatic_speech_recognition( | |
audio=audio_bytes | |
) | |
# Return the result | |
return res |