Spaces:
Running
Running
Rename app.py(bad) to app.py
Browse files- app.py +26 -0
- app.py(bad) +0 -46
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import librosa
|
| 3 |
+
from asr import transcribe_auto, ASR_EXAMPLES, ASR_NOTE # Modify transcribe_auto to auto-detect language
|
| 4 |
+
|
| 5 |
+
# Speech-to-Text Interface without language selection
|
| 6 |
+
mms_transcribe = gr.Interface(
|
| 7 |
+
fn=transcribe_auto, # Function that automatically detects language
|
| 8 |
+
inputs=gr.Audio(),
|
| 9 |
+
outputs="text",
|
| 10 |
+
examples=ASR_EXAMPLES,
|
| 11 |
+
title="Speech-to-Text",
|
| 12 |
+
description="Automatically transcribes audio in either English or Swahili.",
|
| 13 |
+
article=ASR_NOTE,
|
| 14 |
+
allow_flagging="never",
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
# Main Gradio App
|
| 18 |
+
with gr.Blocks() as demo:
|
| 19 |
+
gr.Markdown("<p align='center' style='font-size: 20px;'>MMS Speech-to-Text</p>")
|
| 20 |
+
gr.HTML("<center>Automatically convert speech to text in English or Swahili.</center>")
|
| 21 |
+
|
| 22 |
+
mms_transcribe.render()
|
| 23 |
+
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
demo.queue()
|
| 26 |
+
demo.launch()
|
app.py(bad)
DELETED
|
@@ -1,46 +0,0 @@
|
|
| 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
|
| 9 |
-
detected_lang = identify(audio)
|
| 10 |
-
|
| 11 |
-
# Debug: Print detected language
|
| 12 |
-
print(f"Detected Language: {detected_lang}")
|
| 13 |
-
|
| 14 |
-
# Ensure the detected language is Swahili or English
|
| 15 |
-
if detected_lang.startswith("swh"):
|
| 16 |
-
detected_lang = "swh"
|
| 17 |
-
elif detected_lang.startswith("eng"):
|
| 18 |
-
detected_lang = "eng"
|
| 19 |
-
else:
|
| 20 |
-
return f"Error: Detected language '{detected_lang}' is not supported."
|
| 21 |
-
|
| 22 |
-
# Transcribe using detected language
|
| 23 |
-
return transcribe(audio, lang=detected_lang)
|
| 24 |
-
|
| 25 |
-
# Speech-to-Text Interface with Auto Language Detection
|
| 26 |
-
mms_transcribe = gr.Interface(
|
| 27 |
-
fn=auto_transcribe,
|
| 28 |
-
inputs=gr.Audio(),
|
| 29 |
-
outputs="text",
|
| 30 |
-
examples=ASR_EXAMPLES,
|
| 31 |
-
title="Speech-to-Text (Auto Language Detection)",
|
| 32 |
-
description="Automatically detects whether speech is in Swahili or English and transcribes it.",
|
| 33 |
-
article=ASR_NOTE,
|
| 34 |
-
allow_flagging="never",
|
| 35 |
-
)
|
| 36 |
-
|
| 37 |
-
# Main Gradio App
|
| 38 |
-
with gr.Blocks() as demo:
|
| 39 |
-
gr.Markdown("<p align='center' style='font-size: 20px;'>MMS Speech-to-Text</p>")
|
| 40 |
-
gr.HTML("<center>Automatically detects and transcribes Swahili or English speech.</center>")
|
| 41 |
-
|
| 42 |
-
mms_transcribe.render()
|
| 43 |
-
|
| 44 |
-
if __name__ == "__main__":
|
| 45 |
-
demo.queue()
|
| 46 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|