Spaces:
Sleeping
Sleeping
Update src/core_model/predict.py
Browse files- src/core_model/predict.py +19 -13
src/core_model/predict.py
CHANGED
|
@@ -4,20 +4,26 @@ import torch.nn.functional as F
|
|
| 4 |
from transformers import XLMRobertaTokenizer, XLMRobertaForSequenceClassification
|
| 5 |
|
| 6 |
class MindGuardPredictor:
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
self.model_id = "MohitRajput45/mindguard-xlmr"
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
self.
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
self.
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# --- THE FIX: The English Translation Dictionary ---
|
| 23 |
# Paste the exact dictionary that printed in your Colab terminal here!
|
|
|
|
| 4 |
from transformers import XLMRobertaTokenizer, XLMRobertaForSequenceClassification
|
| 5 |
|
| 6 |
class MindGuardPredictor:
|
| 7 |
+
# 1. Identify the Model Hub ID
|
| 8 |
+
self.model_id = "MohitRajput45/mindguard-xlmr"
|
|
|
|
| 9 |
|
| 10 |
+
# 2. Load the components
|
| 11 |
+
# Note: If your files are in the root of the repo, remove subfolder="final_mindguard_model"
|
| 12 |
+
try:
|
| 13 |
+
self.tokenizer = XLMRobertaTokenizer.from_pretrained(
|
| 14 |
+
self.model_id,
|
| 15 |
+
subfolder="final_mindguard_model"
|
| 16 |
+
)
|
| 17 |
+
self.model = XLMRobertaForSequenceClassification.from_pretrained(
|
| 18 |
+
self.model_id,
|
| 19 |
+
subfolder="final_mindguard_model"
|
| 20 |
+
)
|
| 21 |
+
print("✅ Model and Tokenizer loaded successfully from Hub.")
|
| 22 |
+
except Exception as e:
|
| 23 |
+
print(f"❌ Error loading model: {e}")
|
| 24 |
+
# Fallback attempt without subfolder if the above fails
|
| 25 |
+
self.tokenizer = XLMRobertaTokenizer.from_pretrained(self.model_id)
|
| 26 |
+
self.model = XLMRobertaForSequenceClassification.from_pretrained(self.model_id)
|
| 27 |
|
| 28 |
# --- THE FIX: The English Translation Dictionary ---
|
| 29 |
# Paste the exact dictionary that printed in your Colab terminal here!
|