Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import librosa
|
| 3 |
from asr import transcribe, ASR_EXAMPLES, ASR_NOTE
|
| 4 |
-
from lid import identify # Import
|
| 5 |
|
| 6 |
-
# Function to detect language and transcribe
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Speech-to-Text Interface with Auto Language Detection
|
| 14 |
mms_transcribe = gr.Interface(
|
| 15 |
-
fn=
|
| 16 |
inputs=gr.Audio(),
|
| 17 |
outputs="text",
|
| 18 |
examples=ASR_EXAMPLES,
|
| 19 |
-
title="Speech-to-Text (
|
| 20 |
-
description="
|
| 21 |
article=ASR_NOTE,
|
| 22 |
allow_flagging="never",
|
| 23 |
)
|
|
@@ -25,11 +30,10 @@ mms_transcribe = gr.Interface(
|
|
| 25 |
# Main Gradio App
|
| 26 |
with gr.Blocks() as demo:
|
| 27 |
gr.Markdown("<p align='center' style='font-size: 20px;'>MMS Speech-to-Text</p>")
|
| 28 |
-
gr.HTML("<center>
|
| 29 |
|
| 30 |
mms_transcribe.render()
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|
| 33 |
demo.queue()
|
| 34 |
demo.launch()
|
| 35 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import librosa
|
| 3 |
from asr import transcribe, ASR_EXAMPLES, ASR_NOTE
|
| 4 |
+
from lid import identify # Import Language Identification model
|
| 5 |
|
| 6 |
+
# Function to detect language and transcribe speech
|
| 7 |
+
def auto_transcribe(audio):
|
| 8 |
+
# Detect language (returns language code like "eng" or "swh")
|
| 9 |
+
detected_lang = identify(audio)
|
| 10 |
+
|
| 11 |
+
# Ensure the detected language is Swahili or English
|
| 12 |
+
if detected_lang not in ["eng", "swh"]:
|
| 13 |
+
return "Error: Only English and Swahili are supported."
|
| 14 |
+
|
| 15 |
+
# Transcribe using detected language
|
| 16 |
+
return transcribe(audio, lang=detected_lang)
|
| 17 |
|
| 18 |
# Speech-to-Text Interface with Auto Language Detection
|
| 19 |
mms_transcribe = gr.Interface(
|
| 20 |
+
fn=auto_transcribe,
|
| 21 |
inputs=gr.Audio(),
|
| 22 |
outputs="text",
|
| 23 |
examples=ASR_EXAMPLES,
|
| 24 |
+
title="Speech-to-Text (Auto Language Detection)",
|
| 25 |
+
description="Automatically detects whether speech is in Swahili or English and transcribes it.",
|
| 26 |
article=ASR_NOTE,
|
| 27 |
allow_flagging="never",
|
| 28 |
)
|
|
|
|
| 30 |
# Main Gradio App
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
gr.Markdown("<p align='center' style='font-size: 20px;'>MMS Speech-to-Text</p>")
|
| 33 |
+
gr.HTML("<center>Automatically detects and transcribes Swahili or English speech.</center>")
|
| 34 |
|
| 35 |
mms_transcribe.render()
|
| 36 |
|
| 37 |
if __name__ == "__main__":
|
| 38 |
demo.queue()
|
| 39 |
demo.launch()
|
|
|