File size: 1,959 Bytes
8e73cee f9a373a 8e73cee f9a373a 8e73cee f9a373a 8e73cee 11ad5cc 8e73cee |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import gradio as gr
from transformers import pipeline
import numpy as np
import os
from huggingface_hub import login
import spaces
# Get token from Space secrets
HF_TOKEN = os.environ.get("HF_TOKEN")
if HF_TOKEN:
login(token=HF_TOKEN)
# Load model from your private repo
MODEL_ID = "badrex/JASR" # Change this to match your repo!
transcriber = pipeline("automatic-speech-recognition", model=MODEL_ID)
@spaces.GPU
def transcribe(audio):
sr, y = audio
# Convert to mono if stereo
if y.ndim > 1:
y = y.mean(axis=1)
y = y.astype(np.float32)
y /= np.max(np.abs(y))
return transcriber({"sampling_rate": sr, "raw": y})["text"]
demo = gr.Interface(
fn=transcribe,
inputs=gr.Audio(),
outputs="text",
title="JASR 🐐 Dialectal Arabic ASR",
description="""
<div class="centered-content">
<div>
<p>
By <a href="https://badrex.github.io/" style="color: #2563eb;">Badr al-Absi</a> with ❤️🤍💚
</p>
<br>
<p style="font-size: 15px; line-height: 1.8;">
This is JASR, pronounced Jasir, an automatic speech recognition system optimized for the regional dialects of <i>Jazirat al-Arab</i>, or the Arabian Peninsula. The model is a fine-tune of the speech foundation model <https://huggingface.co/facebook/w2v-bert-2.0" style="color: #FF5349;">w2v-BERT 2.0</a>, a 580M pre-trained speech encoder.
<br>
<p style="font-size: 15px; line-height: 1.8;">
Simply <strong>upload an audio file</strong> 📤 or <strong>record yourself speaking</strong> 🎙️⏺️ to try out the model!
</p>
</div>
</div>
""",
examples=examples if examples else None,
cache_examples=False, # Disable caching to avoid issues
flagging_mode=None,
)
if __name__ == "__main__":
demo.launch() |