Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import numpy as np
|
4 |
+
import os
|
5 |
+
from huggingface_hub import login
|
6 |
+
import spaces
|
7 |
+
|
8 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
9 |
+
if HF_TOKEN:
|
10 |
+
login(token=HF_TOKEN)
|
11 |
+
|
12 |
+
MODEL_ID = "badrex/ASRwanda"
|
13 |
+
transcriber = pipeline("automatic-speech-recognition", model=MODEL_ID)
|
14 |
+
|
15 |
+
@spaces.GPU
|
16 |
+
def transcribe(audio):
|
17 |
+
sr, y = audio
|
18 |
+
# convert to mono if stereo
|
19 |
+
if y.ndim > 1:
|
20 |
+
y = y.mean(axis=1)
|
21 |
+
y = y.astype(np.float32)
|
22 |
+
y /= np.max(np.abs(y))
|
23 |
+
return transcriber({"sampling_rate": sr, "raw": y})["text"]
|
24 |
+
|
25 |
+
|
26 |
+
examples = []
|
27 |
+
examples_dir = "examples"
|
28 |
+
if os.path.exists(examples_dir):
|
29 |
+
for filename in os.listdir(examples_dir):
|
30 |
+
if filename.endswith((".wav", ".mp3", ".ogg")):
|
31 |
+
examples.append([os.path.join(examples_dir, filename)])
|
32 |
+
|
33 |
+
print(f"Found {len(examples)} example files")
|
34 |
+
else:
|
35 |
+
print("Examples directory not found")
|
36 |
+
|
37 |
+
|
38 |
+
demo = gr.Interface(
|
39 |
+
fn=transcribe,
|
40 |
+
inputs=gr.Audio(),
|
41 |
+
outputs="text",
|
42 |
+
title="<div>ASRwanda 🎙️ <br>Speech Recognition for Kinyarwanda</div>",
|
43 |
+
description="""
|
44 |
+
<div class="centered-content">
|
45 |
+
<div>
|
46 |
+
<p>
|
47 |
+
Developed with ❤ by <a href="https://badrex.github.io/" style="color: #2563eb;">Badr al-Absi</a>
|
48 |
+
</p>
|
49 |
+
<br>
|
50 |
+
<p style="font-size: 15px; line-height: 1.8;">
|
51 |
+
Muraho 👋🏼
|
52 |
+
<br>
|
53 |
+
<br>
|
54 |
+
This is a demo for ASRwanda, a Transformer-based automatic speech recognition (ASR) system for Kinyarwanda language.
|
55 |
+
The underlying ASR model was trained on 500 hours of transcribed speech provided by
|
56 |
+
<https://digitalumuganda.com/" style="color: #2563eb;">Digital Umuganda</a> as part of the Kin-ASR-2025 challenge.
|
57 |
+
<br>
|
58 |
+
<p style="font-size: 15px; line-height: 1.8;">
|
59 |
+
Simply <strong>upload an audio file</strong> 📤 or <strong>record yourself speaking</strong> 🎙️⏺️ to try out the model!
|
60 |
+
</p>
|
61 |
+
</div>
|
62 |
+
</div>
|
63 |
+
""",
|
64 |
+
examples=examples if examples else None,
|
65 |
+
cache_examples=False,
|
66 |
+
flagging_mode=None,
|
67 |
+
)
|
68 |
+
|
69 |
+
if __name__ == "__main__":
|
70 |
+
demo.launch()
|