Spaces:
Running on Zero
Running on Zero
Require transformers 5.x to match the builder's hub 1.x
Browse filestransformers 4.x caps huggingface-hub below 1.0; gradio 6 and spaces both
need 1.x, so pip had no solution and the build failed. Also switch to a
string device and tolerate ffmpeg_read having moved in v5.
- app.py +9 -3
- requirements.txt +6 -3
app.py
CHANGED
|
@@ -36,6 +36,9 @@ SAMPLE_RATE = 16000
|
|
| 36 |
CHUNK_LENGTH_S = float(os.environ.get("CHUNK_LENGTH_S", "30"))
|
| 37 |
STRIDE_LENGTH_S = float(os.environ.get("STRIDE_LENGTH_S", "5"))
|
| 38 |
MT_BATCH = int(os.environ.get("MT_BATCH", "16"))
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Gradio owns the process on a Gradio-SDK Space, but it is a FastAPI app
|
| 41 |
# underneath — so the REST routes below are the real interface and the little UI
|
|
@@ -68,10 +71,10 @@ def _load(kind: str):
|
|
| 68 |
token=HF_TOKEN,
|
| 69 |
chunk_length_s=CHUNK_LENGTH_S,
|
| 70 |
stride_length_s=STRIDE_LENGTH_S,
|
| 71 |
-
device=
|
| 72 |
)
|
| 73 |
else:
|
| 74 |
-
obj = pipeline("translation", model=MT_MODEL, token=HF_TOKEN, device=
|
| 75 |
except Exception as e:
|
| 76 |
_errors[kind] = f"{type(e).__name__}: {e}"
|
| 77 |
raise
|
|
@@ -102,7 +105,10 @@ def _decode(raw: bytes) -> np.ndarray:
|
|
| 102 |
Any container -> float32 mono @16k. The backend already sends 16k mono WAV,
|
| 103 |
but decoding defensively costs nothing and keeps the service reusable.
|
| 104 |
"""
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
| 106 |
return ffmpeg_read(raw, SAMPLE_RATE)
|
| 107 |
|
| 108 |
|
|
|
|
| 36 |
CHUNK_LENGTH_S = float(os.environ.get("CHUNK_LENGTH_S", "30"))
|
| 37 |
STRIDE_LENGTH_S = float(os.environ.get("STRIDE_LENGTH_S", "5"))
|
| 38 |
MT_BATCH = int(os.environ.get("MT_BATCH", "16"))
|
| 39 |
+
# "cpu" rather than the old -1: transformers 5 takes a device string. Set
|
| 40 |
+
# ASR_DEVICE=cuda:0 if this ever runs on real GPU hardware.
|
| 41 |
+
DEVICE = os.environ.get("ASR_DEVICE", "cpu")
|
| 42 |
|
| 43 |
# Gradio owns the process on a Gradio-SDK Space, but it is a FastAPI app
|
| 44 |
# underneath — so the REST routes below are the real interface and the little UI
|
|
|
|
| 71 |
token=HF_TOKEN,
|
| 72 |
chunk_length_s=CHUNK_LENGTH_S,
|
| 73 |
stride_length_s=STRIDE_LENGTH_S,
|
| 74 |
+
device=DEVICE,
|
| 75 |
)
|
| 76 |
else:
|
| 77 |
+
obj = pipeline("translation", model=MT_MODEL, token=HF_TOKEN, device=DEVICE)
|
| 78 |
except Exception as e:
|
| 79 |
_errors[kind] = f"{type(e).__name__}: {e}"
|
| 80 |
raise
|
|
|
|
| 105 |
Any container -> float32 mono @16k. The backend already sends 16k mono WAV,
|
| 106 |
but decoding defensively costs nothing and keeps the service reusable.
|
| 107 |
"""
|
| 108 |
+
try:
|
| 109 |
+
from transformers.pipelines.audio_utils import ffmpeg_read
|
| 110 |
+
except ImportError: # moved in transformers 5
|
| 111 |
+
from transformers.audio_utils import ffmpeg_read
|
| 112 |
return ffmpeg_read(raw, SAMPLE_RATE)
|
| 113 |
|
| 114 |
|
requirements.txt
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
# torch, gradio, uvicorn and spaces are installed by the Space builder itself
|
| 2 |
-
# (
|
| 3 |
-
#
|
| 4 |
-
transformers
|
|
|
|
|
|
|
|
|
|
| 5 |
sentencepiece
|
| 6 |
sacremoses
|
|
|
|
| 1 |
# torch, gradio, uvicorn and spaces are installed by the Space builder itself
|
| 2 |
+
# (torch pinned there), so declaring them here only creates resolver conflicts.
|
| 3 |
+
#
|
| 4 |
+
# transformers must be 5.x: 4.x caps huggingface-hub below 1.0, while the
|
| 5 |
+
# builder's gradio 6 / spaces stack requires 1.x. That clash is unsolvable and
|
| 6 |
+
# fails the build outright.
|
| 7 |
+
transformers>=5.0
|
| 8 |
sentencepiece
|
| 9 |
sacremoses
|