Spaces:
Runtime error
Runtime error
Commit
·
236142a
1
Parent(s):
2bf1fd4
Update app.py
Browse files
app.py
CHANGED
@@ -5,13 +5,10 @@ import json
|
|
5 |
from transformers import pipeline
|
6 |
from stitched_model import CombinedModel
|
7 |
|
8 |
-
|
9 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
model = CombinedModel("facebook/mms-1b-all", "Sunbird/sunbird-mul-en-mbart-merged", device=device)
|
12 |
|
13 |
-
|
14 |
-
|
15 |
def transcribe(audio_file_mic=None, audio_file_upload=None):
|
16 |
if audio_file_mic:
|
17 |
audio_file = audio_file_mic
|
@@ -28,18 +25,36 @@ def transcribe(audio_file_mic=None, audio_file_upload=None):
|
|
28 |
|
29 |
with torch.no_grad():
|
30 |
transcription, translation = model({"audio":speech})
|
31 |
-
|
32 |
return transcription, translation[0]
|
33 |
|
34 |
description = '''Luganda to English Speech Translation'''
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
from transformers import pipeline
|
6 |
from stitched_model import CombinedModel
|
7 |
|
|
|
8 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
9 |
|
10 |
model = CombinedModel("facebook/mms-1b-all", "Sunbird/sunbird-mul-en-mbart-merged", device=device)
|
11 |
|
|
|
|
|
12 |
def transcribe(audio_file_mic=None, audio_file_upload=None):
|
13 |
if audio_file_mic:
|
14 |
audio_file = audio_file_mic
|
|
|
25 |
|
26 |
with torch.no_grad():
|
27 |
transcription, translation = model({"audio":speech})
|
28 |
+
|
29 |
return transcription, translation[0]
|
30 |
|
31 |
description = '''Luganda to English Speech Translation'''
|
32 |
|
33 |
+
# Define example audio files
|
34 |
+
example_audio_files = [
|
35 |
+
"audio/luganda.mp3" # Replace with the path to your first example audio file
|
36 |
+
]
|
37 |
+
|
38 |
+
# Generate example inputs and outputs
|
39 |
+
examples = []
|
40 |
+
for audio_file_path in example_audio_files:
|
41 |
+
transcription, translation = transcribe(audio_file_upload=audio_file_path)
|
42 |
+
examples.append({
|
43 |
+
"input": audio_file_path,
|
44 |
+
"output": [transcription, translation]
|
45 |
+
})
|
46 |
+
|
47 |
+
iface = gr.Interface(
|
48 |
+
fn=transcribe,
|
49 |
+
inputs=[
|
50 |
+
gr.Audio(source="microphone", type="filepath", label="Record Audio"),
|
51 |
+
gr.Audio(source="upload", type="filepath", label="Upload Audio")
|
52 |
+
],
|
53 |
+
outputs=[
|
54 |
+
gr.Textbox(label="Transcription"),
|
55 |
+
gr.Textbox(label="Translation")
|
56 |
+
],
|
57 |
+
description=description,
|
58 |
+
examples=examples # Add the examples here
|
59 |
+
)
|
60 |
+
iface.launch()
|