Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -56,14 +56,14 @@ def transcribe(inputs, previous_transcription):
|
|
56 |
return previous_transcription, "Error"
|
57 |
|
58 |
@spaces.GPU
|
59 |
-
def translate_and_transcribe(inputs, previous_transcription):
|
60 |
start_time = time.time()
|
61 |
try:
|
62 |
filename = f"{uuid.uuid4().hex}.wav"
|
63 |
sample_rate, audio_data = inputs
|
64 |
scipy.io.wavfile.write(filename, sample_rate, audio_data)
|
65 |
|
66 |
-
translation = pipe(filename, generate_kwargs={"task": "translate", "language":
|
67 |
|
68 |
previous_transcription += translation
|
69 |
|
@@ -111,10 +111,22 @@ with gr.Blocks() as translate:
|
|
111 |
input_audio_microphone = gr.Audio(streaming=True)
|
112 |
output = gr.Textbox(label="Transcription and Translation", value="")
|
113 |
latency_textbox = gr.Textbox(label="Latency (seconds)", value="0.0", scale=0)
|
|
|
|
|
|
|
|
|
|
|
114 |
with gr.Row():
|
115 |
clear_button = gr.Button("Clear Output")
|
116 |
|
117 |
-
input_audio_microphone.stream(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
clear_button.click(clear, outputs=[output])
|
119 |
|
120 |
with gr.Blocks() as demo:
|
|
|
56 |
return previous_transcription, "Error"
|
57 |
|
58 |
@spaces.GPU
|
59 |
+
def translate_and_transcribe(inputs, previous_transcription, target_language):
|
60 |
start_time = time.time()
|
61 |
try:
|
62 |
filename = f"{uuid.uuid4().hex}.wav"
|
63 |
sample_rate, audio_data = inputs
|
64 |
scipy.io.wavfile.write(filename, sample_rate, audio_data)
|
65 |
|
66 |
+
translation = pipe(filename, generate_kwargs={"task": "translate", "language": target_language} )["text"]
|
67 |
|
68 |
previous_transcription += translation
|
69 |
|
|
|
111 |
input_audio_microphone = gr.Audio(streaming=True)
|
112 |
output = gr.Textbox(label="Transcription and Translation", value="")
|
113 |
latency_textbox = gr.Textbox(label="Latency (seconds)", value="0.0", scale=0)
|
114 |
+
target_language_dropdown = gr.Dropdown(
|
115 |
+
choices=["<|es|>", "<|fr|>", "<|de|>", "<|ja|>", "<|ru|>"],
|
116 |
+
label="Target Language",
|
117 |
+
value="<|es|>"
|
118 |
+
)
|
119 |
with gr.Row():
|
120 |
clear_button = gr.Button("Clear Output")
|
121 |
|
122 |
+
input_audio_microphone.stream(
|
123 |
+
translate_and_transcribe,
|
124 |
+
[input_audio_microphone, output, target_language_dropdown],
|
125 |
+
[output, latency_textbox],
|
126 |
+
time_limit=45,
|
127 |
+
stream_every=2,
|
128 |
+
concurrency_limit=None
|
129 |
+
)
|
130 |
clear_button.click(clear, outputs=[output])
|
131 |
|
132 |
with gr.Blocks() as demo:
|