Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -32,22 +32,17 @@ async def load_model():
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
print("✅ Model loaded successfully")
|
| 51 |
except Exception as e:
|
| 52 |
print(f"❌ Error loading model: {e}")
|
| 53 |
import traceback
|
|
|
|
| 32 |
token=hf_token # Use token for private repo access
|
| 33 |
)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
with open(model_path, 'rb') as f:
|
| 36 |
+
model_data = pickle.load(f)
|
| 37 |
+
|
| 38 |
+
# Handle both dict format and raw model
|
| 39 |
+
if isinstance(model_data, dict):
|
| 40 |
+
model = model_data['model']
|
| 41 |
+
print(f"✅ Model loaded successfully (threshold: {model_data.get('optimal_threshold', 0.5)})")
|
| 42 |
+
else:
|
| 43 |
+
model = model_data
|
| 44 |
+
print("✅ Model loaded successfully")
|
| 45 |
|
|
|
|
| 46 |
except Exception as e:
|
| 47 |
print(f"❌ Error loading model: {e}")
|
| 48 |
import traceback
|