Views
No views yet
| Training Loss | Epoch | Step | Validation Loss | BLEU |
|---|---|---|---|---|
| 1.1851 | 0.8941 | 2000 | 1.1864 | 18.7395 |
| 0.8701 | 1.7881 | 4000 | 1.1268 | 22.3615 |
| 0.566 | 2.6822 | 6000 | 1.1656 | 24.4993 |
| 0.3238 | 3.5762 | 8000 | 1.2711 | 25.1466 |
| 0.1725 | 4.4703 | 10000 | 1.3854 | 24.7036 |
| 0.0821 | 5.3643 | 12000 | 1.4924 | 25.2531 |
| 0.0424 | 6.2584 | 14000 | 1.5961 | 24.4800 |
| 0.018 | 7.1524 | 16000 | 1.6757 | 24.8197 |
| 0.0101 | 8.0465 | 18000 | 1.7439 | 25.1500 |
| 0.0089 | 8.9405 | 20000 | 1.7756 | 25.3308 |
1! pip install transformers datasets torch
2
3import torch
4from transformers import WhisperForConditionalGeneration, WhisperProcessor
5from datasets import load_dataset
6
7# Load model and processor
8device = "cuda:0" if torch.cuda.is_available() else "cpu"
9model = WhisperForConditionalGeneration.from_pretrained("bilalfaye/whisper-medium-wolof-2-english").to(device)
10processor = WhisperProcessor.from_pretrained("bilalfaye/whisper-medium-wolof-2-english")
11
12# Load dataset
13streaming_dataset = load_dataset("bilalfaye/english-wolof-french-dataset", split="train", streaming=True)
14iterator = iter(streaming_dataset)
15sample = next(iterator)
16sample = next(iterator)
17sample = next(iterator)
18
19
20# Preprocess audio
21input_features = processor(sample["wo_audio"]["audio"]["array"],
22 sampling_rate=sample["wo_audio"]["audio"]["sampling_rate"],
23 return_tensors="pt").input_features.to(device)
24
25# Generate transcription
26predicted_ids = model.generate(input_features)
27transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
28
29print("Correct sentence:", sample["wo"])
30print("Transcription:", transcription[0])1! pip install gradio
2
3from transformers import pipeline
4import gradio as gr
5import numpy as np
6
7
8# Load model pipeline
9device = "cuda:0" if torch.cuda.is_available() else "cpu"
10pipe = pipeline(task="automatic-speech-recognition", model="bilalfaye/whisper-medium-wolof-2-english", device=device)
11
12# Function for transcription
13def transcribe(audio):
14 if audio is None:
15 return "No audio provided. Please try again."
16
17 if isinstance(audio, str):
18 waveform, sample_rate = torchaudio.load(audio)
19 elif isinstance(audio, tuple): # Case microphone (Gradio donne un tuple (fichier, sample_rate))
20 waveform, sample_rate = torchaudio.load(audio[0])
21 else:
22 return "Invalid audio input format."
23
24 if waveform.shape[0] > 1:
25 mono_audio = waveform.mean(dim=0, keepdim=True)
26 else:
27 mono_audio = waveform
28
29 target_sample_rate = 16000
30 if sample_rate != target_sample_rate:
31 resampler = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=target_sample_rate)
32 mono_audio = resampler(mono_audio)
33 sample_rate = target_sample_rate
34
35 mono_audio = mono_audio.squeeze(0).numpy().astype(np.float32)
36
37 result = pipe({"array": mono_audio, "sampling_rate": sample_rate})
38 return result['text']
39
40
41# Create Gradio interfaces
42interface = gr.Interface(
43 fn=transcribe,
44 inputs=gr.Audio(sources=["upload", "microphone"], type="filepath"),
45 outputs="text",
46 title="Whisper Medium Wolof Translation",
47 description="Record audio in Wolof and translate it to English using a fine-tuned Whisper medium model.",
48 #live=True,
49)
50
51
52app = gr.TabbedInterface(
53 [interface],
54 ["Use Uploaded File or Microphone"]
55)
56
57app.launch(debug=True, share=True)