Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import numpy as np
|
|
| 6 |
import pickle
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
import os
|
|
|
|
| 9 |
from typing import List, Union
|
| 10 |
|
| 11 |
app = FastAPI(title="Headache Predictor API")
|
|
@@ -30,8 +31,22 @@ async def load_model():
|
|
| 30 |
cache_dir=cache_dir,
|
| 31 |
token=hf_token # Use token for private repo access
|
| 32 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
with open(model_path, 'rb') as f:
|
| 34 |
-
model =
|
|
|
|
| 35 |
print("✅ Model loaded successfully")
|
| 36 |
except Exception as e:
|
| 37 |
print(f"❌ Error loading model: {e}")
|
|
|
|
| 6 |
import pickle
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
import os
|
| 9 |
+
import sys
|
| 10 |
from typing import List, Union
|
| 11 |
|
| 12 |
app = FastAPI(title="Headache Predictor API")
|
|
|
|
| 31 |
cache_dir=cache_dir,
|
| 32 |
token=hf_token # Use token for private repo access
|
| 33 |
)
|
| 34 |
+
|
| 35 |
+
# Load with custom unpickler to handle missing modules
|
| 36 |
+
class CustomUnpickler(pickle.Unpickler):
|
| 37 |
+
def find_class(self, module, name):
|
| 38 |
+
# Redirect src.* imports to current directory
|
| 39 |
+
if module.startswith('src.'):
|
| 40 |
+
module = module.replace('src.', '')
|
| 41 |
+
try:
|
| 42 |
+
return super().find_class(module, name)
|
| 43 |
+
except (ModuleNotFoundError, AttributeError):
|
| 44 |
+
# If module not found, try without the prefix
|
| 45 |
+
return super().find_class(name, name)
|
| 46 |
+
|
| 47 |
with open(model_path, 'rb') as f:
|
| 48 |
+
model = CustomUnpickler(f).load()
|
| 49 |
+
|
| 50 |
print("✅ Model loaded successfully")
|
| 51 |
except Exception as e:
|
| 52 |
print(f"❌ Error loading model: {e}")
|