Spaces:
Sleeping
Sleeping
Kesheratmex
commited on
Commit
·
a4acfba
1
Parent(s):
2c4cd1d
**Improve GPT wrapper loading and HF token handling**
Browse filesAdd `importlib` for dynamic module loading, log detailed errors when the GPT wrapper fails to import, and support multiple environment variable names (`HUGGINGFACE_API_TOKEN`, `HF_API_TOKEN`, `HF_TOKEN`) for the Hugging Face token.
- app.py +6 -1
- gptoss_wrapper.py +7 -1
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import shutil
|
|
| 5 |
import os
|
| 6 |
import cv2
|
| 7 |
import torch
|
|
|
|
| 8 |
|
| 9 |
# Optional PDF reporting: import reportlab safely and set a flag.
|
| 10 |
# REPORTLAB_AVAILABLE will be used by _write_pdf to select the PDF code path.
|
|
@@ -248,7 +249,11 @@ def _load_gptoss_wrapper():
|
|
| 248 |
module = importlib.util.module_from_spec(spec)
|
| 249 |
spec.loader.exec_module(module)
|
| 250 |
return getattr(module, "GPTOSSWrapper", None)
|
| 251 |
-
except Exception:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
return None
|
| 253 |
|
| 254 |
def _build_prompt(frames):
|
|
|
|
| 5 |
import os
|
| 6 |
import cv2
|
| 7 |
import torch
|
| 8 |
+
import importlib
|
| 9 |
|
| 10 |
# Optional PDF reporting: import reportlab safely and set a flag.
|
| 11 |
# REPORTLAB_AVAILABLE will be used by _write_pdf to select the PDF code path.
|
|
|
|
| 249 |
module = importlib.util.module_from_spec(spec)
|
| 250 |
spec.loader.exec_module(module)
|
| 251 |
return getattr(module, "GPTOSSWrapper", None)
|
| 252 |
+
except Exception as e:
|
| 253 |
+
# Print diagnostic info to Space logs so we can see why the wrapper failed to import.
|
| 254 |
+
print(f"DEBUG: failed to load GPT wrapper from {wrapper_path}: {e}")
|
| 255 |
+
import traceback
|
| 256 |
+
traceback.print_exc()
|
| 257 |
return None
|
| 258 |
|
| 259 |
def _build_prompt(frames):
|
gptoss_wrapper.py
CHANGED
|
@@ -41,7 +41,13 @@ class GPTOSSWrapper:
|
|
| 41 |
self.model = model
|
| 42 |
self.request_timeout = 30
|
| 43 |
self.openai_key = os.getenv("OPENAI_API_KEY")
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
self.provider = provider.lower() if provider else "auto"
|
| 46 |
|
| 47 |
if self.provider == "auto":
|
|
|
|
| 41 |
self.model = model
|
| 42 |
self.request_timeout = 30
|
| 43 |
self.openai_key = os.getenv("OPENAI_API_KEY")
|
| 44 |
+
# Accept multiple HF token environment variable names for compatibility:
|
| 45 |
+
# HUGGINGFACE_API_TOKEN, HF_API_TOKEN, or HF_TOKEN (used by some HF examples)
|
| 46 |
+
self.hf_token = (
|
| 47 |
+
os.getenv("HUGGINGFACE_API_TOKEN")
|
| 48 |
+
or os.getenv("HF_API_TOKEN")
|
| 49 |
+
or os.getenv("HF_TOKEN")
|
| 50 |
+
)
|
| 51 |
self.provider = provider.lower() if provider else "auto"
|
| 52 |
|
| 53 |
if self.provider == "auto":
|