Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,11 +34,24 @@ def analyze_text(model_label, text):
|
|
| 34 |
try:
|
| 35 |
result = analyzer(text)[0]
|
| 36 |
label = result.get("label", "UNKNOWN")
|
| 37 |
-
score = round(result.get("score", 3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
return f"{label} ({score})"
|
| 39 |
except Exception as e:
|
| 40 |
return f"Error during inference: {e}"
|
| 41 |
|
|
|
|
| 42 |
# Build Gradio interface
|
| 43 |
with gr.Blocks(title="CIS1160 – Inference Explorer") as demo:
|
| 44 |
gr.Markdown(
|
|
|
|
| 34 |
try:
|
| 35 |
result = analyzer(text)[0]
|
| 36 |
label = result.get("label", "UNKNOWN")
|
| 37 |
+
score = round(result.get("score", 0), 3)
|
| 38 |
+
|
| 39 |
+
# Fix model-specific labels for clarity
|
| 40 |
+
if "cardiffnlp/twitter-roberta-base-sentiment" in model_name:
|
| 41 |
+
label_map = {"LABEL_0": "Negative", "LABEL_1": "Neutral", "LABEL_2": "Positive"}
|
| 42 |
+
label = label_map.get(label, label)
|
| 43 |
+
|
| 44 |
+
elif "nlptown/bert-base-multilingual-uncased-sentiment" in model_name:
|
| 45 |
+
label = label.replace("LABEL_", "⭐️ ") # optional, fun visual
|
| 46 |
+
|
| 47 |
+
# Strip out any extra text or URLs that sneak into outputs
|
| 48 |
+
label = str(label).split("https://")[0].strip()
|
| 49 |
+
|
| 50 |
return f"{label} ({score})"
|
| 51 |
except Exception as e:
|
| 52 |
return f"Error during inference: {e}"
|
| 53 |
|
| 54 |
+
|
| 55 |
# Build Gradio interface
|
| 56 |
with gr.Blocks(title="CIS1160 – Inference Explorer") as demo:
|
| 57 |
gr.Markdown(
|