Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -37,6 +37,31 @@ pipe = pipeline(
|
|
37 |
device=device,
|
38 |
)
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
@spaces.GPU
|
41 |
def transcribe(inputs, previous_transcription):
|
42 |
start_time = time.time()
|
@@ -86,8 +111,8 @@ with gr.Blocks() as microphone:
|
|
86 |
latency_textbox = gr.Textbox(label="Latency (seconds)", value="0.0", scale=0)
|
87 |
with gr.Row():
|
88 |
clear_button = gr.Button("Clear Output")
|
89 |
-
|
90 |
-
input_audio_microphone.stream(
|
91 |
clear_button.click(clear, outputs=[output])
|
92 |
|
93 |
with gr.Blocks() as file:
|
|
|
37 |
device=device,
|
38 |
)
|
39 |
|
40 |
+
@spaces.GPU
|
41 |
+
def stream_transcribe(stream, new_chunk):
|
42 |
+
start_time = time.time()
|
43 |
+
try:
|
44 |
+
sr, y = new_chunk
|
45 |
+
|
46 |
+
# Convert to mono if stereo
|
47 |
+
if y.ndim > 1:
|
48 |
+
y = y.mean(axis=1)
|
49 |
+
|
50 |
+
y = y.astype(np.float32)
|
51 |
+
y /= np.max(np.abs(y))
|
52 |
+
|
53 |
+
if stream is not None:
|
54 |
+
stream = np.concatenate([stream, y])
|
55 |
+
else:
|
56 |
+
stream = y
|
57 |
+
|
58 |
+
end_time = time.time()
|
59 |
+
latency = end_time - start_time
|
60 |
+
return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"], f"{latency:.2f}"
|
61 |
+
except Exception as e:
|
62 |
+
print(f"Error during Transcription: {e}")
|
63 |
+
return previous_transcription, "Error"
|
64 |
+
|
65 |
@spaces.GPU
|
66 |
def transcribe(inputs, previous_transcription):
|
67 |
start_time = time.time()
|
|
|
111 |
latency_textbox = gr.Textbox(label="Latency (seconds)", value="0.0", scale=0)
|
112 |
with gr.Row():
|
113 |
clear_button = gr.Button("Clear Output")
|
114 |
+
state = gr.State()
|
115 |
+
input_audio_microphone.stream(stream_transcribe, [state, input_audio_microphone], [state, output, latency_textbox], time_limit=45, stream_every=1, concurrency_limit=None)
|
116 |
clear_button.click(clear, outputs=[output])
|
117 |
|
118 |
with gr.Blocks() as file:
|