Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
692769a
1
Parent(s):
a2ed037
fix: move numpy and soundfile imports inside transcribe function and clean up audio buffer handling
Browse files
app.py
CHANGED
@@ -23,19 +23,17 @@ def load_model():
|
|
23 |
print(f"Model loaded on device: {model.device}")
|
24 |
return model
|
25 |
|
26 |
-
import numpy as np
|
27 |
-
import soundfile as sf
|
28 |
-
audio_buffer = []
|
29 |
|
30 |
@spaces.GPU(duration=120)
|
31 |
def transcribe(audio, state=""):
|
32 |
# Load the model inside the GPU worker process
|
|
|
|
|
33 |
model = load_model()
|
34 |
|
35 |
if audio is None or isinstance(audio, int):
|
36 |
print(f"Skipping invalid audio input: {type(audio)}")
|
37 |
return state, state
|
38 |
-
|
39 |
print(f"Received audio input of type: {type(audio)}")
|
40 |
print(f"Audio shape: {audio.shape if isinstance(audio, np.ndarray) else 'N/A'}")
|
41 |
# Append NumPy array to buffer
|
@@ -84,8 +82,6 @@ def transcribe(audio, state=""):
|
|
84 |
print(f"Error processing audio: {e}")
|
85 |
# return state, state
|
86 |
|
87 |
-
# Clear buffer
|
88 |
-
audio_buffer = []
|
89 |
new_state = state + " " + transcription if state else transcription
|
90 |
return new_state, new_state
|
91 |
return state, state
|
|
|
23 |
print(f"Model loaded on device: {model.device}")
|
24 |
return model
|
25 |
|
|
|
|
|
|
|
26 |
|
27 |
@spaces.GPU(duration=120)
|
28 |
def transcribe(audio, state=""):
|
29 |
# Load the model inside the GPU worker process
|
30 |
+
import numpy as np
|
31 |
+
import soundfile as sf
|
32 |
model = load_model()
|
33 |
|
34 |
if audio is None or isinstance(audio, int):
|
35 |
print(f"Skipping invalid audio input: {type(audio)}")
|
36 |
return state, state
|
|
|
37 |
print(f"Received audio input of type: {type(audio)}")
|
38 |
print(f"Audio shape: {audio.shape if isinstance(audio, np.ndarray) else 'N/A'}")
|
39 |
# Append NumPy array to buffer
|
|
|
82 |
print(f"Error processing audio: {e}")
|
83 |
# return state, state
|
84 |
|
|
|
|
|
85 |
new_state = state + " " + transcription if state else transcription
|
86 |
return new_state, new_state
|
87 |
return state, state
|