root commited on
Commit
a5f1898
Β·
1 Parent(s): 0fde622
Files changed (2) hide show
  1. app.py +68 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Preload both models
5
+ models = {
6
+ "moulsot_v0.1_2500": pipeline("automatic-speech-recognition", model="01Yassine/moulsot_v0.1_2500"),
7
+ "moulsot_v0.2_1000": pipeline("automatic-speech-recognition", model="01Yassine/moulsot_v0.2_1000")
8
+ }
9
+
10
+ # Adjust generation config for both
11
+ for m in models.values():
12
+ m.model.generation_config.input_ids = m.model.generation_config.forced_decoder_ids
13
+ m.model.generation_config.forced_decoder_ids = None
14
+
15
+
16
+ def transcribe(audio, selected_model):
17
+ if audio is None:
18
+ return "Please record or upload an audio file.", "Please record or upload an audio file."
19
+
20
+ pipe = models[selected_model]
21
+ other_model = [k for k in models if k != selected_model][0]
22
+
23
+ # Run inference
24
+ result_selected = pipe(audio)["text"]
25
+ result_other = models[other_model](audio)["text"]
26
+
27
+ return result_selected, result_other
28
+
29
+
30
+ title = "πŸŽ™οΈ Moulsot Whisper ASR Comparison"
31
+ description = """
32
+ Compare two fine-tuned Whisper models for **Moroccan ASR**:
33
+ - 🟩 **moulsot_v0.1_2500**
34
+ - 🟦 **moulsot_v0.2_1000**
35
+
36
+ You can **record** or **upload** an audio sample, then see transcriptions from both models side by side.
37
+ """
38
+
39
+ with gr.Blocks(title=title) as demo:
40
+ gr.Markdown(f"# {title}\n{description}")
41
+
42
+ with gr.Row():
43
+ audio_input = gr.Audio(
44
+ sources=["microphone", "upload"],
45
+ type="filepath",
46
+ label="🎀 Record or Upload Audio"
47
+ )
48
+ model_choice = gr.Radio(
49
+ ["moulsot_v0.1_2500", "moulsot_v0.2_1000"],
50
+ label="Choose Primary Model",
51
+ value="moulsot_v0.1_2500"
52
+ )
53
+
54
+ transcribe_btn = gr.Button("πŸš€ Transcribe")
55
+
56
+ with gr.Row():
57
+ output_selected = gr.Textbox(label="🟩 Model 1 Output")
58
+ output_other = gr.Textbox(label="🟦 Model 2 Output")
59
+
60
+ transcribe_btn.click(
61
+ fn=transcribe,
62
+ inputs=[audio_input, model_choice],
63
+ outputs=[output_selected, output_other]
64
+ )
65
+
66
+ # For local testing
67
+ if __name__ == "__main__":
68
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch