Spaces:
Sleeping
Sleeping
jefffffff9 Claude Sonnet 4.6 commited on
Commit ·
ca322f7
1
Parent(s): d2183cd
Fix: robust Whisper import + upgrade Gradio to fix API schema crash
Browse files- app.py: cascading import fallback for AutoModelForSpeechSeq2Seq which
is not top-level exported in all transformers 5.x builds; also handles
dtype vs torch_dtype rename across versions
- README.md: sdk_version 5.9.1 → 5.25.0 to fix TypeError in
gradio_client json_schema_to_python_type (bug present through ~5.10)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🌾
|
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: "5.
|
| 8 |
app_file: app.py
|
| 9 |
hardware: cpu-basic
|
| 10 |
pinned: false
|
|
|
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: "5.25.0"
|
| 8 |
app_file: app.py
|
| 9 |
hardware: cpu-basic
|
| 10 |
pinned: false
|
app.py
CHANGED
|
@@ -82,9 +82,16 @@ if HF_TOKEN:
|
|
| 82 |
def _do_load_whisper():
|
| 83 |
global _whisper_model, _whisper_processor, _adapter_manager, _model_status
|
| 84 |
import torch
|
| 85 |
-
|
| 86 |
-
#
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
from src.engine.adapter_manager import AdapterManager
|
| 89 |
|
| 90 |
_model_status = "loading…"
|
|
@@ -92,11 +99,20 @@ def _do_load_whisper():
|
|
| 92 |
_whisper_processor = AutoProcessor.from_pretrained(
|
| 93 |
WHISPER_MODEL_ID, token=HF_TOKEN
|
| 94 |
)
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
_whisper_model.eval()
|
| 101 |
|
| 102 |
# Create the AdapterManager wrapping the base model
|
|
|
|
| 82 |
def _do_load_whisper():
|
| 83 |
global _whisper_model, _whisper_processor, _adapter_manager, _model_status
|
| 84 |
import torch
|
| 85 |
+
from transformers import AutoProcessor
|
| 86 |
+
# AutoModelForSpeechSeq2Seq is not always exported at the transformers top level
|
| 87 |
+
# depending on the version; fall back through known-good alternatives.
|
| 88 |
+
try:
|
| 89 |
+
from transformers import AutoModelForSpeechSeq2Seq as _ModelCls
|
| 90 |
+
except ImportError:
|
| 91 |
+
try:
|
| 92 |
+
from transformers import AutoModelForConditionalGeneration as _ModelCls
|
| 93 |
+
except ImportError:
|
| 94 |
+
from transformers.models.whisper.modeling_whisper import WhisperForConditionalGeneration as _ModelCls
|
| 95 |
from src.engine.adapter_manager import AdapterManager
|
| 96 |
|
| 97 |
_model_status = "loading…"
|
|
|
|
| 99 |
_whisper_processor = AutoProcessor.from_pretrained(
|
| 100 |
WHISPER_MODEL_ID, token=HF_TOKEN
|
| 101 |
)
|
| 102 |
+
# `dtype` is the transformers 5.x name; `torch_dtype` works on 4.x.
|
| 103 |
+
# Try the new name first, fall back if the version doesn't accept it.
|
| 104 |
+
try:
|
| 105 |
+
_whisper_model = _ModelCls.from_pretrained(
|
| 106 |
+
WHISPER_MODEL_ID,
|
| 107 |
+
dtype=torch.float32,
|
| 108 |
+
token=HF_TOKEN,
|
| 109 |
+
)
|
| 110 |
+
except TypeError:
|
| 111 |
+
_whisper_model = _ModelCls.from_pretrained(
|
| 112 |
+
WHISPER_MODEL_ID,
|
| 113 |
+
torch_dtype=torch.float32,
|
| 114 |
+
token=HF_TOKEN,
|
| 115 |
+
)
|
| 116 |
_whisper_model.eval()
|
| 117 |
|
| 118 |
# Create the AdapterManager wrapping the base model
|