Instructions to use AhmedZaky1/whisper-small-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AhmedZaky1/whisper-small-v1 with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("AhmedZaky1/whisper-small-v1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Studio
How to use AhmedZaky1/whisper-small-v1 with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for AhmedZaky1/whisper-small-v1 to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for AhmedZaky1/whisper-small-v1 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for AhmedZaky1/whisper-small-v1 to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="AhmedZaky1/whisper-small-v1", max_seq_length=2048, )
| base_model: unsloth/whisper-small | |
| tags: | |
| - text-generation-inference | |
| - transformers | |
| - unsloth | |
| - whisper | |
| - trl | |
| license: apache-2.0 | |
| language: | |
| - en | |
| # Use Model | |
| ``` | |
| import torch | |
| import numpy as np | |
| import re | |
| import jiwer | |
| import librosa | |
| from transformers import WhisperProcessor, WhisperForConditionalGeneration | |
| # TEXT NORMALIZATION | |
| def normalize_text(text): | |
| text = text.lower() | |
| text = re.sub(r"[^\w\s]", "", text) | |
| text = " ".join(text.split()) | |
| return text | |
| # METRICS | |
| def calculate_metrics(ref, hyp): | |
| ref_n = normalize_text(ref) | |
| hyp_n = normalize_text(hyp) | |
| return { | |
| "reference": ref_n, | |
| "hypothesis": hyp_n, | |
| "wer": jiwer.wer(ref_n, hyp_n), | |
| "cer": jiwer.cer(ref_n, hyp_n) | |
| } | |
| # LOAD MODEL FROM HF | |
| def load_whisper(model_name, device="cuda"): | |
| print(f"Loading Whisper model from HuggingFace: {model_name}") | |
| processor = WhisperProcessor.from_pretrained(model_name) | |
| model = WhisperForConditionalGeneration.from_pretrained(model_name) | |
| return processor, model.to(device).eval() | |
| # TRANSCRIBE AUDIO | |
| def transcribe_audio(audio_path, processor, model, device="cuda"): | |
| waveform, sr = librosa.load(audio_path, sr=16000) | |
| inputs = processor( | |
| waveform, | |
| sampling_rate=sr, | |
| return_tensors="pt" | |
| ).input_features.to(device) | |
| with torch.no_grad(): | |
| predicted_ids = model.generate(inputs) | |
| transcription = processor.batch_decode( | |
| predicted_ids, | |
| skip_special_tokens=True | |
| )[0] | |
| return transcription | |
| # MAIN | |
| def main(): | |
| # SET YOUR AUDIO FILE & REFERENCE TEXT HERE | |
| audio_path = "" | |
| reference_text = "" | |
| # 2️ YOUR MODEL NAME | |
| model_name = "AhmedZaky1/whisper-small-v1" | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| # Load model | |
| processor, model = load_whisper(model_name, device) | |
| # Transcribe | |
| print("\nTranscribing audio...") | |
| prediction = transcribe_audio(audio_path, processor, model, device) | |
| # Compute metrics | |
| metrics = calculate_metrics(reference_text, prediction) | |
| print("\n==============================") | |
| print("REFERENCE:", metrics["reference"]) | |
| print("PREDICTION:", metrics["hypothesis"]) | |
| print(f"WER: {metrics['wer'] * 100:.2f}%") | |
| print(f"CER: {metrics['cer'] * 100:.2f}%") | |
| print("==============================") | |
| # Run script | |
| if __name__ == "__main__": | |
| main() | |
| ``` | |