sgAtdbd commited on
Commit
5582337
·
verified ·
1 Parent(s): e06c835

Update models/hate_speech_classifier.py

Browse files
Files changed (1) hide show
  1. models/hate_speech_classifier.py +33 -3
models/hate_speech_classifier.py CHANGED
@@ -7,11 +7,35 @@ import torch
7
  from deep_translator import GoogleTranslator
8
 
9
  class HateSpeechClassifier:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def __init__(self):
11
- base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
12
- models_dir = os.path.join(base_dir, "models", "model_weights", "custom_models")
 
13
 
14
- # Initialize translator
 
 
 
15
  self.translator = GoogleTranslator(source='bn', target='en')
16
 
17
  # Use multiple pretrained models for better accuracy
@@ -28,6 +52,12 @@ class HateSpeechClassifier:
28
  }
29
  }
30
 
 
 
 
 
 
 
31
  # English custom model paths
32
  self.english_model_path = os.path.join(models_dir, "english_model.pkl")
33
  self.english_vectorizer_path = os.path.join(models_dir, "english_vectorizer.pkl")
 
7
  from deep_translator import GoogleTranslator
8
 
9
  class HateSpeechClassifier:
10
+ # def __init__(self):
11
+ # base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
12
+ # models_dir = os.path.join(base_dir, "models", "model_weights", "custom_models")
13
+
14
+ # # Initialize translator
15
+ # self.translator = GoogleTranslator(source='bn', target='en')
16
+
17
+ # # Use multiple pretrained models for better accuracy
18
+ # self.pretrained_models = {
19
+ # "primary": {
20
+ # "name": "facebook/roberta-hate-speech-dynabench-r4-target",
21
+ # "pipeline": None,
22
+ # "weight": 0.6
23
+ # },
24
+ # "secondary": {
25
+ # "name": "cardiffnlp/twitter-roberta-base-hate-latest",
26
+ # "pipeline": None,
27
+ # "weight": 0.4
28
+ # }
29
+ # }
30
  def __init__(self):
31
+ # Get absolute path to model weights
32
+ base_dir = Path(__file__).parent
33
+ self.model_dir = base_dir / 'model_weights' / 'custom_models'
34
 
35
+ # For Hugging Face Spaces, also check environment
36
+ if not self.model_dir.exists():
37
+ # Try alternative paths for deployed environment
38
+ self.model_dir = Path('/app/models/model_weights/custom_models')
39
  self.translator = GoogleTranslator(source='bn', target='en')
40
 
41
  # Use multiple pretrained models for better accuracy
 
52
  }
53
  }
54
 
55
+ print(f"Model directory: {self.model_dir}")
56
+ print(f"Model directory exists: {self.model_dir.exists()}")
57
+
58
+ if self.model_dir.exists():
59
+ print(f"Files in model directory: {list(self.model_dir.iterdir())}")
60
+
61
  # English custom model paths
62
  self.english_model_path = os.path.join(models_dir, "english_model.pkl")
63
  self.english_vectorizer_path = os.path.join(models_dir, "english_vectorizer.pkl")