Spaces:
Running
Running
tried to fix transcribing
Browse files- pipeline/transcriber.py +14 -20
- requirements-spaces.txt +7 -0
pipeline/transcriber.py
CHANGED
|
@@ -220,14 +220,21 @@ class Transcriber:
|
|
| 220 |
|
| 221 |
if not _TORCH_AVAILABLE:
|
| 222 |
try:
|
|
|
|
| 223 |
from huggingface_hub import snapshot_download
|
| 224 |
|
| 225 |
-
|
| 226 |
-
repo_id
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
logger.info("Moonshine ASR cache download completed.")
|
| 232 |
except Exception as exc:
|
| 233 |
logger.error(
|
|
@@ -400,25 +407,12 @@ class Transcriber:
|
|
| 400 |
)
|
| 401 |
return ""
|
| 402 |
|
| 403 |
-
# Quick host resolution check: avoid repeated DNS failures
|
| 404 |
endpoint = "https://api-inference.huggingface.co/models/openai/whisper-small"
|
| 405 |
-
hf_host = "api-inference.huggingface.co"
|
| 406 |
|
| 407 |
if self._remote_ok is False:
|
| 408 |
-
logger.debug("Remote HF
|
| 409 |
return ""
|
| 410 |
|
| 411 |
-
if self._remote_ok is None:
|
| 412 |
-
try:
|
| 413 |
-
socket.getaddrinfo(hf_host, 443)
|
| 414 |
-
self._remote_ok = True
|
| 415 |
-
except Exception:
|
| 416 |
-
logger.warning(
|
| 417 |
-
"Cannot resolve Hugging Face inference host; disabling remote transcription until next restart."
|
| 418 |
-
)
|
| 419 |
-
self._remote_ok = False
|
| 420 |
-
return ""
|
| 421 |
-
|
| 422 |
try:
|
| 423 |
headers = {
|
| 424 |
"Authorization": f"Bearer {HF_TOKEN}",
|
|
|
|
| 220 |
|
| 221 |
if not _TORCH_AVAILABLE:
|
| 222 |
try:
|
| 223 |
+
import inspect
|
| 224 |
from huggingface_hub import snapshot_download
|
| 225 |
|
| 226 |
+
snapshot_kwargs = {
|
| 227 |
+
"repo_id": TRANSCRIBE_MODEL_ID,
|
| 228 |
+
"local_files_only": False,
|
| 229 |
+
"repo_type": "model",
|
| 230 |
+
}
|
| 231 |
+
sig = inspect.signature(snapshot_download)
|
| 232 |
+
if "token" in sig.parameters:
|
| 233 |
+
snapshot_kwargs["token"] = HF_TOKEN or None
|
| 234 |
+
elif "use_auth_token" in sig.parameters:
|
| 235 |
+
snapshot_kwargs["use_auth_token"] = HF_TOKEN or None
|
| 236 |
+
|
| 237 |
+
snapshot_download(**snapshot_kwargs)
|
| 238 |
logger.info("Moonshine ASR cache download completed.")
|
| 239 |
except Exception as exc:
|
| 240 |
logger.error(
|
|
|
|
| 407 |
)
|
| 408 |
return ""
|
| 409 |
|
|
|
|
| 410 |
endpoint = "https://api-inference.huggingface.co/models/openai/whisper-small"
|
|
|
|
| 411 |
|
| 412 |
if self._remote_ok is False:
|
| 413 |
+
logger.debug("Remote HF has previously failed; skipping remote transcription.")
|
| 414 |
return ""
|
| 415 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
try:
|
| 417 |
headers = {
|
| 418 |
"Authorization": f"Bearer {HF_TOKEN}",
|
requirements-spaces.txt
CHANGED
|
@@ -9,5 +9,12 @@ huggingface_hub
|
|
| 9 |
soundfile
|
| 10 |
requests
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Optional utilities
|
| 13 |
# Keep the core app lightweight and use fallback or remote inference when needed.
|
|
|
|
| 9 |
soundfile
|
| 10 |
requests
|
| 11 |
|
| 12 |
+
# Local ASR and VAD dependencies for deployed Spaces
|
| 13 |
+
torch>=2.4.0
|
| 14 |
+
transformers>=4.56,<5.3,!=5.0.*,!=5.1.*
|
| 15 |
+
# Optional: silero VAD and ONNX for real-time speech boundary detection
|
| 16 |
+
silero-vad
|
| 17 |
+
onnxruntime>=1.16.0
|
| 18 |
+
|
| 19 |
# Optional utilities
|
| 20 |
# Keep the core app lightweight and use fallback or remote inference when needed.
|