Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -113,17 +113,19 @@ async def load_model():
|
|
| 113 |
"""Load model and vectorizers on startup"""
|
| 114 |
global model, tfidf_word, tfidf_char
|
| 115 |
|
| 116 |
-
print("Loading model from Hugging Face...")
|
| 117 |
-
|
| 118 |
-
# Download model
|
| 119 |
-
model_path = hf_hub_download(
|
| 120 |
-
repo_id="aqibtahir/cookie-classifier-lr-tfidf",
|
| 121 |
-
filename="LR_TFIDF+NAME.joblib"
|
| 122 |
-
)
|
| 123 |
-
model = joblib.load(model_path)
|
| 124 |
-
|
| 125 |
-
# Try to load vectorizers (they should be in the same directory or uploaded separately)
|
| 126 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
tfidf_word_path = hf_hub_download(
|
| 128 |
repo_id="aqibtahir/cookie-classifier-lr-tfidf",
|
| 129 |
filename="tfidf_word.joblib"
|
|
@@ -134,10 +136,14 @@ async def load_model():
|
|
| 134 |
)
|
| 135 |
tfidf_word = joblib.load(tfidf_word_path)
|
| 136 |
tfidf_char = joblib.load(tfidf_char_path)
|
| 137 |
-
print("β
|
|
|
|
|
|
|
| 138 |
except Exception as e:
|
| 139 |
-
print(f"
|
| 140 |
-
|
|
|
|
|
|
|
| 141 |
|
| 142 |
# Request/Response models
|
| 143 |
class CookieRequest(BaseModel):
|
|
|
|
| 113 |
"""Load model and vectorizers on startup"""
|
| 114 |
global model, tfidf_word, tfidf_char
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
try:
|
| 117 |
+
print("π Loading model from Hugging Face...")
|
| 118 |
+
|
| 119 |
+
# Download model
|
| 120 |
+
model_path = hf_hub_download(
|
| 121 |
+
repo_id="aqibtahir/cookie-classifier-lr-tfidf",
|
| 122 |
+
filename="LR_TFIDF+NAME.joblib"
|
| 123 |
+
)
|
| 124 |
+
model = joblib.load(model_path)
|
| 125 |
+
print("β Model loaded")
|
| 126 |
+
|
| 127 |
+
# Load vectorizers
|
| 128 |
+
print("π Loading vectorizers...")
|
| 129 |
tfidf_word_path = hf_hub_download(
|
| 130 |
repo_id="aqibtahir/cookie-classifier-lr-tfidf",
|
| 131 |
filename="tfidf_word.joblib"
|
|
|
|
| 136 |
)
|
| 137 |
tfidf_word = joblib.load(tfidf_word_path)
|
| 138 |
tfidf_char = joblib.load(tfidf_char_path)
|
| 139 |
+
print("β Vectorizers loaded")
|
| 140 |
+
print("π API ready to serve predictions!")
|
| 141 |
+
|
| 142 |
except Exception as e:
|
| 143 |
+
print(f"β Error during startup: {e}")
|
| 144 |
+
import traceback
|
| 145 |
+
traceback.print_exc()
|
| 146 |
+
raise
|
| 147 |
|
| 148 |
# Request/Response models
|
| 149 |
class CookieRequest(BaseModel):
|