Spaces:
Running
Running
Update alisto_project/backend/ingest_reddit.py
Browse files
alisto_project/backend/ingest_reddit.py
CHANGED
|
@@ -33,29 +33,31 @@ db.init_app(app)
|
|
| 33 |
|
| 34 |
# 2. Load Models
|
| 35 |
print("Loading ALISTO Brains from Cloud...")
|
| 36 |
-
|
| 37 |
-
MODEL_ID = "Quivara/alisto-brain
|
| 38 |
|
| 39 |
try:
|
| 40 |
-
# Load Tokenizer
|
| 41 |
-
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 42 |
|
| 43 |
-
# Load Model (
|
| 44 |
-
roberta_model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID, num_labels=2)
|
| 45 |
|
| 46 |
device = torch.device("cpu")
|
| 47 |
roberta_model.to(device)
|
| 48 |
roberta_model.eval()
|
| 49 |
-
print(f"✅ Context Expert loaded from {MODEL_ID}")
|
| 50 |
|
| 51 |
except Exception as e:
|
| 52 |
print(f"❌ Error loading Model: {e}")
|
|
|
|
| 53 |
exit()
|
| 54 |
|
|
|
|
| 55 |
# B. TF-IDF (The Gatekeeper)
|
| 56 |
try:
|
| 57 |
print("Downloading Gatekeeper (TF-IDF)...")
|
| 58 |
-
#
|
| 59 |
tfidf_path = hf_hub_download(repo_id=MODEL_ID, filename="tfidf_ensemble.pkl")
|
| 60 |
|
| 61 |
with open(tfidf_path, 'rb') as f:
|
|
|
|
| 33 |
|
| 34 |
# 2. Load Models
|
| 35 |
print("Loading ALISTO Brains from Cloud...")
|
| 36 |
+
|
| 37 |
+
MODEL_ID = "Quivara/alisto-brain"
|
| 38 |
|
| 39 |
try:
|
| 40 |
+
# Load Tokenizer (Add subfolder argument)
|
| 41 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, subfolder="roberta_model")
|
| 42 |
|
| 43 |
+
# Load Model (Add subfolder argument)
|
| 44 |
+
roberta_model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID, subfolder="roberta_model", num_labels=2)
|
| 45 |
|
| 46 |
device = torch.device("cpu")
|
| 47 |
roberta_model.to(device)
|
| 48 |
roberta_model.eval()
|
| 49 |
+
print(f"✅ Context Expert loaded from {MODEL_ID} (roberta_model folder)")
|
| 50 |
|
| 51 |
except Exception as e:
|
| 52 |
print(f"❌ Error loading Model: {e}")
|
| 53 |
+
# Emergency Fallback to generic model so app doesn't crash
|
| 54 |
exit()
|
| 55 |
|
| 56 |
+
|
| 57 |
# B. TF-IDF (The Gatekeeper)
|
| 58 |
try:
|
| 59 |
print("Downloading Gatekeeper (TF-IDF)...")
|
| 60 |
+
# TF-IDF is likely in the root, so no subfolder needed
|
| 61 |
tfidf_path = hf_hub_download(repo_id=MODEL_ID, filename="tfidf_ensemble.pkl")
|
| 62 |
|
| 63 |
with open(tfidf_path, 'rb') as f:
|