Update app.py
Browse files
app.py
CHANGED
|
@@ -5,19 +5,17 @@ import os
|
|
| 5 |
from huggingface_hub import login
|
| 6 |
import spaces
|
| 7 |
|
| 8 |
-
# Get token from Space secrets
|
| 9 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 10 |
if HF_TOKEN:
|
| 11 |
login(token=HF_TOKEN)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
MODEL_ID = "badrex/JASR" # Change this to match your repo!
|
| 15 |
transcriber = pipeline("automatic-speech-recognition", model=MODEL_ID)
|
| 16 |
|
| 17 |
@spaces.GPU
|
| 18 |
def transcribe(audio):
|
| 19 |
sr, y = audio
|
| 20 |
-
#
|
| 21 |
if y.ndim > 1:
|
| 22 |
y = y.mean(axis=1)
|
| 23 |
y = y.astype(np.float32)
|
|
@@ -25,7 +23,6 @@ def transcribe(audio):
|
|
| 25 |
return transcriber({"sampling_rate": sr, "raw": y})["text"]
|
| 26 |
|
| 27 |
|
| 28 |
-
# Manually prepare example file paths without metadata
|
| 29 |
examples = []
|
| 30 |
examples_dir = "examples"
|
| 31 |
if os.path.exists(examples_dir):
|
|
@@ -42,7 +39,6 @@ demo = gr.Interface(
|
|
| 42 |
fn=transcribe,
|
| 43 |
inputs=gr.Audio(),
|
| 44 |
outputs="text",
|
| 45 |
-
#theme="gstaff/sketch",
|
| 46 |
title="JASR 🐐 Dialectal Arabic Speech Recognition",
|
| 47 |
description="""
|
| 48 |
<div class="centered-content">
|
|
@@ -55,7 +51,8 @@ demo = gr.Interface(
|
|
| 55 |
Marhaba 👋🏼
|
| 56 |
<br>
|
| 57 |
<br>
|
| 58 |
-
This is a demo for JASR, pronounced <i>Jasir</i>,
|
|
|
|
| 59 |
<br>
|
| 60 |
<p style="font-size: 15px; line-height: 1.8;">
|
| 61 |
Simply <strong>upload an audio file</strong> 📤 or <strong>record yourself speaking</strong> 🎙️⏺️ to try out the model!
|
|
@@ -64,7 +61,7 @@ demo = gr.Interface(
|
|
| 64 |
</div>
|
| 65 |
""",
|
| 66 |
examples=examples if examples else None,
|
| 67 |
-
cache_examples=False,
|
| 68 |
flagging_mode=None,
|
| 69 |
)
|
| 70 |
|
|
|
|
| 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/JASR"
|
|
|
|
| 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)
|
|
|
|
| 23 |
return transcriber({"sampling_rate": sr, "raw": y})["text"]
|
| 24 |
|
| 25 |
|
|
|
|
| 26 |
examples = []
|
| 27 |
examples_dir = "examples"
|
| 28 |
if os.path.exists(examples_dir):
|
|
|
|
| 39 |
fn=transcribe,
|
| 40 |
inputs=gr.Audio(),
|
| 41 |
outputs="text",
|
|
|
|
| 42 |
title="JASR 🐐 Dialectal Arabic Speech Recognition",
|
| 43 |
description="""
|
| 44 |
<div class="centered-content">
|
|
|
|
| 51 |
Marhaba 👋🏼
|
| 52 |
<br>
|
| 53 |
<br>
|
| 54 |
+
This is a demo for JASR, pronounced <i>Jasir</i>, a Transformer-based automatic speech recognition (ASR) system for dialectal Arabic.
|
| 55 |
+
The current running instance is optimized for the regional dialects of <i>Jazirat al-Arab</i>, or the Arabian Peninsula.
|
| 56 |
<br>
|
| 57 |
<p style="font-size: 15px; line-height: 1.8;">
|
| 58 |
Simply <strong>upload an audio file</strong> 📤 or <strong>record yourself speaking</strong> 🎙️⏺️ to try out the model!
|
|
|
|
| 61 |
</div>
|
| 62 |
""",
|
| 63 |
examples=examples if examples else None,
|
| 64 |
+
cache_examples=False,
|
| 65 |
flagging_mode=None,
|
| 66 |
)
|
| 67 |
|