abhaynb92 commited on
Commit
2bd7932
·
verified ·
1 Parent(s): 6a5f60d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -6,9 +6,11 @@ from model import EmotionClassifier
6
  MODEL_NAME = "microsoft/deberta-v3-base"
7
 
8
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
 
 
9
  model = EmotionClassifier(MODEL_NAME)
10
 
11
- # important! map_location=cpu
12
  model.load_state_dict(torch.load("best_deberta_base.bin", map_location="cpu"))
13
  model.eval()
14
 
@@ -19,23 +21,24 @@ def predict(text):
19
  text,
20
  padding=True,
21
  truncation=True,
22
- return_tensors="pt",
23
- max_length=128
24
  )
 
25
  with torch.no_grad():
26
  logits = model(
27
  encoded["input_ids"],
28
  encoded["attention_mask"]
29
  )
30
- probs = torch.sigmoid(logits).cpu().numpy()[0]
31
-
32
- return {emotion: float(prob) for emotion, prob in zip(EMOTIONS, probs)}
33
 
34
  demo = gr.Interface(
35
  fn=predict,
36
  inputs="text",
37
  outputs="label",
38
- title="Emotion Classifier DeBERTa-v3-base"
39
  )
40
 
41
  demo.launch()
 
6
  MODEL_NAME = "microsoft/deberta-v3-base"
7
 
8
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
9
+
10
+ # Build model with correct structure
11
  model = EmotionClassifier(MODEL_NAME)
12
 
13
+ # Load checkpoint — MUST MATCH KEYS NOW
14
  model.load_state_dict(torch.load("best_deberta_base.bin", map_location="cpu"))
15
  model.eval()
16
 
 
21
  text,
22
  padding=True,
23
  truncation=True,
24
+ max_length=128,
25
+ return_tensors="pt"
26
  )
27
+
28
  with torch.no_grad():
29
  logits = model(
30
  encoded["input_ids"],
31
  encoded["attention_mask"]
32
  )
33
+ probs = torch.sigmoid(logits).numpy()[0]
34
+
35
+ return {emo: float(p) for emo, p in zip(EMOTIONS, probs)}
36
 
37
  demo = gr.Interface(
38
  fn=predict,
39
  inputs="text",
40
  outputs="label",
41
+ title="Emotion Classifier DeBERTa"
42
  )
43
 
44
  demo.launch()