Automatic Speech Recognition
Transformers
Safetensors
Arabic
whisper
quran
arabic
asr
speech-recognition
fine-tuned
quranic-arabic
tajweed
islam
Eval Results (legacy)
Instructions to use wasimlhr/whisper-quran-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use wasimlhr/whisper-quran-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="wasimlhr/whisper-quran-v1")# Load model directly from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq processor = AutoProcessor.from_pretrained("wasimlhr/whisper-quran-v1") model = AutoModelForSpeechSeq2Seq.from_pretrained("wasimlhr/whisper-quran-v1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Remove broken handler.py (needs WAV decoding fix)
Browse files- handler.py +0 -70
handler.py
DELETED
|
@@ -1,70 +0,0 @@
|
|
| 1 |
-
from typing import Dict, Any
|
| 2 |
-
import torch
|
| 3 |
-
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 4 |
-
|
| 5 |
-
class EndpointHandler:
|
| 6 |
-
def __init__(self, path=""):
|
| 7 |
-
"""
|
| 8 |
-
Initialize the handler with the model
|
| 9 |
-
"""
|
| 10 |
-
self.processor = WhisperProcessor.from_pretrained(path, language="ar", task="transcribe")
|
| 11 |
-
self.model = WhisperForConditionalGeneration.from_pretrained(
|
| 12 |
-
path,
|
| 13 |
-
torch_dtype=torch.float16
|
| 14 |
-
).to("cuda" if torch.cuda.is_available() else "cpu")
|
| 15 |
-
self.model.eval()
|
| 16 |
-
|
| 17 |
-
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
| 18 |
-
"""
|
| 19 |
-
Process the input data and return predictions with word timestamps
|
| 20 |
-
|
| 21 |
-
Args:
|
| 22 |
-
data: dictionary with 'inputs' key containing audio bytes
|
| 23 |
-
|
| 24 |
-
Returns:
|
| 25 |
-
dictionary with 'text' and 'words' (with timestamps)
|
| 26 |
-
"""
|
| 27 |
-
# Get audio from request
|
| 28 |
-
inputs = data.pop("inputs", data)
|
| 29 |
-
|
| 30 |
-
# Process audio
|
| 31 |
-
audio_inputs = self.processor(
|
| 32 |
-
inputs,
|
| 33 |
-
sampling_rate=16000,
|
| 34 |
-
return_tensors="pt"
|
| 35 |
-
)
|
| 36 |
-
|
| 37 |
-
input_features = audio_inputs.input_features.to(self.model.device)
|
| 38 |
-
|
| 39 |
-
# Generate with timestamps
|
| 40 |
-
with torch.no_grad():
|
| 41 |
-
generated_ids = self.model.generate(
|
| 42 |
-
input_features,
|
| 43 |
-
language="ar",
|
| 44 |
-
task="transcribe",
|
| 45 |
-
max_new_tokens=448,
|
| 46 |
-
return_timestamps=True # Enable word timestamps
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
-
# Decode with word-level timestamps
|
| 50 |
-
result = self.processor.batch_decode(
|
| 51 |
-
generated_ids,
|
| 52 |
-
skip_special_tokens=True,
|
| 53 |
-
return_timestamps='word' # Request word-level
|
| 54 |
-
)[0]
|
| 55 |
-
|
| 56 |
-
# Format response
|
| 57 |
-
text = result.get('text', '')
|
| 58 |
-
words = []
|
| 59 |
-
|
| 60 |
-
for chunk in result.get('chunks', []):
|
| 61 |
-
words.append({
|
| 62 |
-
"text": chunk['text'],
|
| 63 |
-
"start": chunk['timestamp'][0],
|
| 64 |
-
"end": chunk['timestamp'][1]
|
| 65 |
-
})
|
| 66 |
-
|
| 67 |
-
return {
|
| 68 |
-
"text": text,
|
| 69 |
-
"words": words
|
| 70 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|