Spaces:
Running on Zero
Running on Zero
Improve text encoder API error detection: validate .npy paths and detect error messages
Browse files
kimodo/model/text_encoder_api.py
CHANGED
|
@@ -52,15 +52,27 @@ class TextEncoderAPI:
|
|
| 52 |
candidates = [result]
|
| 53 |
|
| 54 |
for item in candidates:
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
if isinstance(item, dict):
|
| 58 |
for key in ("value", "path", "name"):
|
| 59 |
value = item.get(key)
|
| 60 |
if isinstance(value, str) and value:
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
raise RuntimeError(f"Text encoder API returned unexpected payload: {
|
| 64 |
|
| 65 |
def __call__(self, texts):
|
| 66 |
"""Encode text prompts into tensors.
|
|
|
|
| 52 |
candidates = [result]
|
| 53 |
|
| 54 |
for item in candidates:
|
| 55 |
+
# Check for error messages first (e.g., "## Encoder initialization failed")
|
| 56 |
+
if isinstance(item, str):
|
| 57 |
+
if item and (item.startswith("##") or "failed" in item.lower() or "error" in item.lower()):
|
| 58 |
+
raise RuntimeError(f"Text encoder API error: {item}")
|
| 59 |
+
if item and item.endswith(".npy"):
|
| 60 |
+
return item
|
| 61 |
+
if item:
|
| 62 |
+
# Log unexpected string for debugging
|
| 63 |
+
print(f"[text_encoder_api] unexpected string response: {item[:100]}")
|
| 64 |
+
|
| 65 |
if isinstance(item, dict):
|
| 66 |
for key in ("value", "path", "name"):
|
| 67 |
value = item.get(key)
|
| 68 |
if isinstance(value, str) and value:
|
| 69 |
+
# Check for errors in dict values too
|
| 70 |
+
if value.startswith("##") or "failed" in value.lower() or "error" in value.lower():
|
| 71 |
+
raise RuntimeError(f"Text encoder API error: {value}")
|
| 72 |
+
if value.endswith(".npy"):
|
| 73 |
+
return value
|
| 74 |
|
| 75 |
+
raise RuntimeError(f"Text encoder API returned unexpected payload: {result!r}")
|
| 76 |
|
| 77 |
def __call__(self, texts):
|
| 78 |
"""Encode text prompts into tensors.
|