Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,18 +83,27 @@ def run_sentiment_with_selected_model(text, model_name):
|
|
| 83 |
outputs = model(**inputs)
|
| 84 |
|
| 85 |
logits = outputs.logits
|
| 86 |
-
probs =
|
| 87 |
pred = torch.argmax(probs, dim=-1).item()
|
| 88 |
|
| 89 |
-
#
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
else:
|
| 93 |
-
label = "
|
| 94 |
|
| 95 |
emoji = "✅" if "positive" in label.lower() else "❌" if "negative" in label.lower() else "⚠️"
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
| 98 |
|
| 99 |
# ---------------- Gradio UI ----------------
|
| 100 |
background_css = """
|
|
|
|
| 83 |
outputs = model(**inputs)
|
| 84 |
|
| 85 |
logits = outputs.logits
|
| 86 |
+
probs = F.softmax(logits, dim=-1)
|
| 87 |
pred = torch.argmax(probs, dim=-1).item()
|
| 88 |
|
| 89 |
+
# Custom label mapping
|
| 90 |
+
label_map = {
|
| 91 |
+
"assemblyai/bert-large-uncased-sst2": {0: "Negative", 1: "Positive"},
|
| 92 |
+
"sohan-ai/sentiment-analysis-model-amazon-reviews": {0: "Negative", 1: "Positive"},
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
if model_name in label_map:
|
| 96 |
+
label = label_map[model_name][pred]
|
| 97 |
+
elif model.config.id2label:
|
| 98 |
+
label = model.config.id2label.get(pred, f"LABEL_{pred}")
|
| 99 |
else:
|
| 100 |
+
label = f"LABEL_{pred}"
|
| 101 |
|
| 102 |
emoji = "✅" if "positive" in label.lower() else "❌" if "negative" in label.lower() else "⚠️"
|
| 103 |
+
|
| 104 |
+
# Add confidence score
|
| 105 |
+
confidence = probs[0][pred].item() * 100
|
| 106 |
+
return f"{emoji} '{text}' -> {label} ({confidence:.1f}%)"
|
| 107 |
|
| 108 |
# ---------------- Gradio UI ----------------
|
| 109 |
background_css = """
|