Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -20,11 +20,16 @@ except ImportError:
|
|
20 |
|
21 |
# --- Configuration ---
|
22 |
# Model path is set to sojka
|
23 |
-
MODEL_PATH = os.getenv("MODEL_PATH", "AndromedaPL/sojka")
|
|
|
|
|
24 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
25 |
LABELS = ["self-harm", "hate", "vulgar", "sex", "crime"]
|
26 |
MAX_SEQ_LENGTH = 512
|
27 |
|
|
|
|
|
|
|
28 |
# Thresholds are now hardcoded
|
29 |
THRESHOLDS = {
|
30 |
"self-harm": 0.5,
|
@@ -38,11 +43,11 @@ THRESHOLDS = {
|
|
38 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
39 |
logger = logging.getLogger(__name__)
|
40 |
|
41 |
-
def load_model_and_tokenizer(model_path: str, device: str) -> Tuple[AutoModelForSequenceClassification, AutoTokenizer]:
|
42 |
"""Load the trained model and tokenizer"""
|
43 |
logger.info(f"Loading model from {model_path}")
|
44 |
|
45 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
46 |
|
47 |
if tokenizer.pad_token is None:
|
48 |
if tokenizer.eos_token:
|
@@ -84,7 +89,7 @@ def load_model_and_tokenizer(model_path: str, device: str) -> Tuple[AutoModelFor
|
|
84 |
|
85 |
# --- Load model globally ---
|
86 |
try:
|
87 |
-
model, tokenizer = load_model_and_tokenizer(MODEL_PATH, DEVICE)
|
88 |
model_loaded = True
|
89 |
except Exception as e:
|
90 |
logger.error(f"FATAL: Failed to load the model from {MODEL_PATH}: {e}")
|
|
|
20 |
|
21 |
# --- Configuration ---
|
22 |
# Model path is set to sojka
|
23 |
+
MODEL_PATH = os.getenv("MODEL_PATH", "AndromedaPL/sojka")
|
24 |
+
TOKENIZER_PATH = os.getenv("MODEL_PATH", "sdadas/mmlw-roberta-base")
|
25 |
+
|
26 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
27 |
LABELS = ["self-harm", "hate", "vulgar", "sex", "crime"]
|
28 |
MAX_SEQ_LENGTH = 512
|
29 |
|
30 |
+
|
31 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
32 |
+
|
33 |
# Thresholds are now hardcoded
|
34 |
THRESHOLDS = {
|
35 |
"self-harm": 0.5,
|
|
|
43 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
44 |
logger = logging.getLogger(__name__)
|
45 |
|
46 |
+
def load_model_and_tokenizer(model_path: str, tokenizer_path: str, device: str) -> Tuple[AutoModelForSequenceClassification, AutoTokenizer]:
|
47 |
"""Load the trained model and tokenizer"""
|
48 |
logger.info(f"Loading model from {model_path}")
|
49 |
|
50 |
+
tokenizer = AutoTokenizer.from_pretrained(tokenizer_path, use_fast=True)
|
51 |
|
52 |
if tokenizer.pad_token is None:
|
53 |
if tokenizer.eos_token:
|
|
|
89 |
|
90 |
# --- Load model globally ---
|
91 |
try:
|
92 |
+
model, tokenizer = load_model_and_tokenizer(MODEL_PATH, TOKENIZER_PATH, DEVICE)
|
93 |
model_loaded = True
|
94 |
except Exception as e:
|
95 |
logger.error(f"FATAL: Failed to load the model from {MODEL_PATH}: {e}")
|