Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 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 |
-
|
| 23 |
-
|
| 24 |
)
|
|
|
|
| 25 |
with torch.no_grad():
|
| 26 |
logits = model(
|
| 27 |
encoded["input_ids"],
|
| 28 |
encoded["attention_mask"]
|
| 29 |
)
|
| 30 |
-
probs = torch.sigmoid(logits).
|
| 31 |
-
|
| 32 |
-
return {
|
| 33 |
|
| 34 |
demo = gr.Interface(
|
| 35 |
fn=predict,
|
| 36 |
inputs="text",
|
| 37 |
outputs="label",
|
| 38 |
-
title="Emotion Classifier
|
| 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()
|