Spaces:
Sleeping
Sleeping
launch
Browse files
app.py
CHANGED
@@ -12,7 +12,10 @@ translation_model = MBartForConditionalGeneration.from_pretrained("facebook/mbar
|
|
12 |
translation_tokenizer = MBart50Tokenizer.from_pretrained("facebook/mbart-large-50-many-to-many-mmt", src_lang="ar_AR")
|
13 |
|
14 |
def transcribe_audio(audio):
|
15 |
-
|
|
|
|
|
|
|
16 |
audio_array, sr = librosa.load(audio, sr=16000)
|
17 |
|
18 |
# Tokenize the audio file
|
@@ -44,16 +47,16 @@ def translate_text(text):
|
|
44 |
|
45 |
return translated_text
|
46 |
|
47 |
-
# Create
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
57 |
|
58 |
demo.launch()
|
59 |
-
demo.launch(api=True, share=True)
|
|
|
12 |
translation_tokenizer = MBart50Tokenizer.from_pretrained("facebook/mbart-large-50-many-to-many-mmt", src_lang="ar_AR")
|
13 |
|
14 |
def transcribe_audio(audio):
|
15 |
+
if not audio:
|
16 |
+
return "No audio file provided", "No translation available"
|
17 |
+
|
18 |
+
# Load the audio file
|
19 |
audio_array, sr = librosa.load(audio, sr=16000)
|
20 |
|
21 |
# Tokenize the audio file
|
|
|
47 |
|
48 |
return translated_text
|
49 |
|
50 |
+
# Create Gradio Blocks for better UI
|
51 |
+
with gr.Blocks() as demo:
|
52 |
+
gr.Markdown("# Speech-to-Text and Translation")
|
53 |
+
gr.Markdown("Upload an audio file to transcribe and translate it from Darija to English.")
|
54 |
+
|
55 |
+
audio_input = gr.Audio(type="filepath", label="Upload or Record Audio")
|
56 |
+
submit_button = gr.Button("Submit")
|
57 |
+
transcription_output = gr.Textbox(label="Transcription (Darija)")
|
58 |
+
translation_output = gr.Textbox(label="Translation (English)")
|
59 |
+
|
60 |
+
submit_button.click(fn=transcribe_audio, inputs=audio_input, outputs=[transcription_output, translation_output])
|
61 |
|
62 |
demo.launch()
|
|