Spaces:
Sleeping
Sleeping
ZeroGPU: spaces shim
Browse files- app.py +11 -3
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,8 +1,15 @@
|
|
| 1 |
-
"""Smart Turn Detection — Hugging Face Space demo (ONNX
|
| 2 |
-
Runs the exported 8s model: raw 16k waveform -> P(turn complete).
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import onnxruntime as ort
|
| 5 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
SR, WIN = 16000, 8
|
| 8 |
N = SR * WIN # 128000
|
|
@@ -19,12 +26,13 @@ def prob_complete(wav, sr):
|
|
| 19 |
mx = np.abs(wav).max()
|
| 20 |
if mx > 0:
|
| 21 |
wav = wav / mx
|
| 22 |
-
x = wav[-N:] # last
|
| 23 |
buf = np.zeros((1, N), np.float32)
|
| 24 |
buf[0, N - len(x):] = x # right-align (left-pad)
|
| 25 |
return float(SESS.run(None, {"waveform": buf})[0][0])
|
| 26 |
|
| 27 |
|
|
|
|
| 28 |
def predict(audio, threshold):
|
| 29 |
if audio is None:
|
| 30 |
return "Record or upload some speech.", None
|
|
|
|
| 1 |
+
"""Smart Turn Detection — Hugging Face Space demo (ONNX).
|
| 2 |
+
Runs the exported 8s model: raw 16k waveform -> P(turn complete).
|
| 3 |
+
Inference is CPU-only ONNX; `spaces.GPU` is just to satisfy the ZeroGPU runtime."""
|
| 4 |
import numpy as np
|
| 5 |
import onnxruntime as ort
|
| 6 |
import gradio as gr
|
| 7 |
+
try:
|
| 8 |
+
import spaces # ZeroGPU runtime
|
| 9 |
+
gpu = spaces.GPU(duration=10)
|
| 10 |
+
except Exception: # local / CPU spaces: no-op decorator
|
| 11 |
+
def gpu(f):
|
| 12 |
+
return f
|
| 13 |
|
| 14 |
SR, WIN = 16000, 8
|
| 15 |
N = SR * WIN # 128000
|
|
|
|
| 26 |
mx = np.abs(wav).max()
|
| 27 |
if mx > 0:
|
| 28 |
wav = wav / mx
|
| 29 |
+
x = wav[-N:] # last 8s
|
| 30 |
buf = np.zeros((1, N), np.float32)
|
| 31 |
buf[0, N - len(x):] = x # right-align (left-pad)
|
| 32 |
return float(SESS.run(None, {"waveform": buf})[0][0])
|
| 33 |
|
| 34 |
|
| 35 |
+
@gpu
|
| 36 |
def predict(audio, threshold):
|
| 37 |
if audio is None:
|
| 38 |
return "Record or upload some speech.", None
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
gradio
|
| 2 |
onnxruntime>=1.17
|
| 3 |
numpy
|
|
|
|
| 1 |
+
spaces
|
| 2 |
gradio
|
| 3 |
onnxruntime>=1.17
|
| 4 |
numpy
|