Instructions to use KhiredNetworks/PakUrdu-Conversational-ASR with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use KhiredNetworks/PakUrdu-Conversational-ASR with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Download inference_example.py from KhiredNetworks/PakUrdu-Conversational-ASR: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/KhiredNetworks/PakUrdu-Conversational-ASR/resolve/main/inference_example.py
- Command line
-
hf download hf://KhiredNetworks/PakUrdu-Conversational-ASR/inference_example.py
-
curl -L -o inference_example.py https://huggingface.co/KhiredNetworks/PakUrdu-Conversational-ASR/resolve/main/inference_example.py
1.25 kB
| #!/usr/bin/env python3 | |
| """Transcribe one Urdu call-audio file with PakUrdu-Conversational-ASR-r12. | |
| Usage: | |
| python inference_example.py call.wav [more.wav ...] | |
| Loads the public base model from the HF hub, applies this LoRA adapter, | |
| merges, and decodes with the certified settings (language=ur, greedy). | |
| """ | |
| import sys | |
| import soundfile as sf | |
| import torch | |
| from peft import PeftModel | |
| from transformers import WhisperForConditionalGeneration, WhisperProcessor | |
| BASE = "openai/whisper-large-v3-turbo" | |
| ADAPTER = "KhiredNetworks/PakUrdu-Conversational-ASR" | |
| if len(sys.argv) < 2: | |
| sys.exit(__doc__) | |
| processor = WhisperProcessor.from_pretrained(BASE) | |
| model = WhisperForConditionalGeneration.from_pretrained(BASE) | |
| model = PeftModel.from_pretrained(model, ADAPTER).merge_and_unload() | |
| for path in sys.argv[1:]: | |
| speech, sr = sf.read(path, dtype="float32") | |
| if speech.ndim > 1: | |
| speech = speech.mean(axis=1) | |
| inputs = processor(speech, sampling_rate=sr, return_tensors="pt") | |
| with torch.no_grad(): | |
| ids = model.generate(inputs.input_features, language="ur", | |
| task="transcribe", do_sample=False) | |
| text = processor.batch_decode(ids, skip_special_tokens=True)[0].strip() | |
| print(f"{path}: {text}") | |