Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from transformers import pipeline
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Create a pipeline for speech recognition using the chosen model
|
6 |
+
pipe = pipeline(model="tarteel-ai/whisper-base-ar-quran",
|
7 |
+
use_auth_token=os.environ["HF_TARTEEL_TOKEN"]) # change to "your-username/the-name-you-picked"
|
8 |
+
|
9 |
+
# Define a function that transcribes audio using the pipeline
|
10 |
+
def transcribe(audio):
|
11 |
+
text = pipe(audio)["text"]
|
12 |
+
return text
|
13 |
+
|
14 |
+
# Create an interface for real-time speech recognition
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=transcribe,
|
17 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
18 |
+
outputs="text",
|
19 |
+
title="Whisper Base for Quranic Arabic",
|
20 |
+
description="Realtime demo for Quran speech recognition using a fine-tuned Whisper base model.",
|
21 |
+
)
|
22 |
+
|
23 |
+
# Launch the interface
|
24 |
+
iface.launch()
|