Automatic Speech Recognition
Transformers
Safetensors
cohere_asr
arabic
asr
stt
speech-to-text
speech-recognition
arabic-asr
transcription
arabic-dialects
modern-standard-arabic
msa
gulf-arabic
emirati-arabic
saudi-arabic
egyptian-arabic
levantine-arabic
maghrebi-arabic
darija
iraqi-arabic
yemeni-arabic
code-switching
word-timestamps
encoder-decoder
ctc
sirocco
custom_code
Eval Results (legacy)
Instructions to use AI71ai/Sirocco-ASR-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AI71ai/Sirocco-ASR-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="AI71ai/Sirocco-ASR-v1", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq processor = AutoProcessor.from_pretrained("AI71ai/Sirocco-ASR-v1", trust_remote_code=True) model = AutoModelForSpeechSeq2Seq.from_pretrained("AI71ai/Sirocco-ASR-v1", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download handler.py from AI71ai/Sirocco-ASR-v1: direct link, hf CLI and curl.
- Browser
- Download file 3.03 kB
-
https://huggingface.co/AI71ai/Sirocco-ASR-v1/resolve/main/handler.py
- Command line
-
hf download hf://AI71ai/Sirocco-ASR-v1/handler.py
-
curl -L -o handler.py https://huggingface.co/AI71ai/Sirocco-ASR-v1/resolve/main/handler.py
3.03 kB
| # SPDX-License-Identifier: CC-BY-NC-4.0 | |
| """A custom handler for managed inference endpoints that serve a model repository through its own handler.py | |
| (Hugging Face Inference Endpoints). It calls the model's own decoder, model.transcribe(), one request at a time. | |
| The repository's requirements.txt lists what the handler needs beside the endpoint's own image. Checked by calling | |
| it locally the way the endpoint toolkit does; not yet run on the managed service. | |
| Requests: the audio file as the request body with its audio content type (audio/wav, audio/flac, audio/mpeg, ...) | |
| and the options as query parameters (?digits=true&word_timestamps=true), or JSON {"inputs": "<the file in base64>", | |
| "parameters": {...}}. Options: digits, latin, word_timestamps, confidence (true or false, default false). The answer | |
| is {"text": ...}, plus "words" [{"word", "start", "end"}] and "confidence" when asked. | |
| """ | |
| from __future__ import annotations | |
| import base64 | |
| import math | |
| import sys | |
| import tempfile | |
| import torch | |
| from transformers import AutoModelForSpeechSeq2Seq | |
| OPTIONS = ("digits", "latin", "word_timestamps", "confidence") | |
| def as_bool(name: str, value) -> bool: | |
| if isinstance(value, bool): | |
| return value | |
| if str(value).strip().lower() in ("true", "1", "yes", "false", "0", "no", ""): | |
| return str(value).strip().lower() in ("true", "1", "yes") | |
| raise ValueError(f"{name} must be true or false, not {value!r}") | |
| class EndpointHandler: | |
| def __init__(self, path: str = ""): | |
| gpu = torch.cuda.is_available() # on a GPU the weights' own bfloat16 (do not pass dtype=None: float32) | |
| cpu = {} if gpu else {"dtype": torch.float32} | |
| model = AutoModelForSpeechSeq2Seq.from_pretrained(path, trust_remote_code=True, **cpu) | |
| self.model = model.to("cuda" if gpu else "cpu").eval() | |
| self.load_audio = sys.modules[type(model).__module__].load_audio # the loader of the model's own code | |
| def __call__(self, data: dict) -> dict: | |
| audio, params = data.get("inputs"), data.get("parameters") or {} | |
| if isinstance(audio, str): | |
| audio = base64.b64decode(audio) | |
| if not isinstance(audio, (bytes, bytearray)) or not audio: | |
| raise ValueError("send the audio file as the request body, or as base64 in inputs") | |
| with tempfile.NamedTemporaryFile() as f: | |
| f.write(audio) | |
| f.flush() | |
| try: | |
| wave = self.load_audio(f.name) | |
| except Exception as e: | |
| raise ValueError(f"the body could not be read as audio ({type(e).__name__})") from e | |
| if wave.size == 0: | |
| raise ValueError("the audio holds no samples") | |
| out = self.model.transcribe(wave, **{k: as_bool(k, params.get(k, False)) for k in OPTIONS}) | |
| if not isinstance(out, dict): | |
| return {"text": out} | |
| if out.get("confidence") is not None and not math.isfinite(out["confidence"]): | |
| out["confidence"] = None # a few samples of audio: no score to give | |
| return out | |