MohitRajput45 commited on
Commit
f220034
·
verified ·
1 Parent(s): cda171e

Update src/core_model/predict.py

Browse files
Files changed (1) hide show
  1. 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
- # The __init__ function runs automatically the moment you create a MindGuardPredictor object.
8
- def __init__(self, model_path=None):
9
- self.model_id = "MohitRajput45/mindguard-xlmr"
10
 
11
- # If your weights are inside 'final_mindguard_model' folder on HF Hub:
12
- # Use the subfolder parameter
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
 
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!