aqibtahir commited on
Commit
4cea15f
Β·
verified Β·
1 Parent(s): 31b1043

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +19 -13
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("βœ“ Model and vectorizers loaded successfully!")
 
 
138
  except Exception as e:
139
- print(f"⚠️ Warning: Could not load vectorizers: {e}")
140
- print("API will work with limited functionality")
 
 
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):