Spaces:
Running
Running
Erik Sarriegui commited on
Commit ·
5353e5f
1
Parent(s): 07a53a7
commit
Browse files- frontend/src/components/ClusterCard.jsx +2 -16
- main.py +4 -14
frontend/src/components/ClusterCard.jsx
CHANGED
|
@@ -62,34 +62,20 @@ export default function ClusterCard({ cluster }) {
|
|
| 62 |
{article.title}
|
| 63 |
</h4>
|
| 64 |
<div className="flex flex-wrap gap-2">
|
| 65 |
-
{
|
| 66 |
-
{article.is_clickbait === true && (
|
| 67 |
<span className="text-[10px] uppercase font-bold text-red-400 bg-red-900/30 border border-red-900/50 px-1.5 py-0.5 rounded">
|
| 68 |
Clickbait
|
| 69 |
</span>
|
| 70 |
)}
|
| 71 |
-
{article.
|
| 72 |
-
<span className="text-[10px] uppercase font-bold text-emerald-400 bg-emerald-900/30 border border-emerald-900/50 px-1.5 py-0.5 rounded">
|
| 73 |
-
Objective
|
| 74 |
-
</span>
|
| 75 |
-
)}
|
| 76 |
-
|
| 77 |
-
{/* Sensationalism Label */}
|
| 78 |
-
{article.is_sensationalist === true && (
|
| 79 |
<span className="text-[10px] uppercase font-bold text-amber-400 bg-amber-900/30 border border-amber-900/50 px-1.5 py-0.5 rounded">
|
| 80 |
Sensationalist
|
| 81 |
</span>
|
| 82 |
)}
|
| 83 |
-
{article.is_sensationalist === false && (
|
| 84 |
-
<span className="text-[10px] uppercase font-bold text-slate-400 bg-slate-800 border border-slate-700 px-1.5 py-0.5 rounded">
|
| 85 |
-
Neutral
|
| 86 |
-
</span>
|
| 87 |
-
)}
|
| 88 |
</div>
|
| 89 |
</div>
|
| 90 |
<ExternalLink className="w-4 h-4 text-slate-500 shrink-0 group-hover:text-blue-400 mt-1" />
|
| 91 |
</div>
|
| 92 |
-
{/* Info footer */}
|
| 93 |
<div className="mt-2 flex items-center gap-2 text-xs text-slate-500">
|
| 94 |
<span className="font-semibold text-slate-400">{article.newspaper}</span>
|
| 95 |
<span>•</span>
|
|
|
|
| 62 |
{article.title}
|
| 63 |
</h4>
|
| 64 |
<div className="flex flex-wrap gap-2">
|
| 65 |
+
{article.is_clickbait && (
|
|
|
|
| 66 |
<span className="text-[10px] uppercase font-bold text-red-400 bg-red-900/30 border border-red-900/50 px-1.5 py-0.5 rounded">
|
| 67 |
Clickbait
|
| 68 |
</span>
|
| 69 |
)}
|
| 70 |
+
{article.is_sensationalist && (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
<span className="text-[10px] uppercase font-bold text-amber-400 bg-amber-900/30 border border-amber-900/50 px-1.5 py-0.5 rounded">
|
| 72 |
Sensationalist
|
| 73 |
</span>
|
| 74 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
</div>
|
| 76 |
</div>
|
| 77 |
<ExternalLink className="w-4 h-4 text-slate-500 shrink-0 group-hover:text-blue-400 mt-1" />
|
| 78 |
</div>
|
|
|
|
| 79 |
<div className="mt-2 flex items-center gap-2 text-xs text-slate-500">
|
| 80 |
<span className="font-semibold text-slate-400">{article.newspaper}</span>
|
| 81 |
<span>•</span>
|
main.py
CHANGED
|
@@ -172,9 +172,8 @@ def get_clusters():
|
|
| 172 |
"newspaper": row.get('newspaper', 'Unknown'),
|
| 173 |
"url": row.get('article_url', '#'),
|
| 174 |
"newspaper_url": row.get('newspaper_url', '#'),
|
| 175 |
-
|
| 176 |
-
"
|
| 177 |
-
"is_sensationalist": (str(row.get('is_sensationalist')).lower() == 'true' or row.get('is_sensationalist') is True) if pd.notna(row.get('is_sensationalist')) else None
|
| 178 |
})
|
| 179 |
|
| 180 |
# Size calc
|
|
@@ -247,22 +246,13 @@ def analyze_article(request: AnalyzeRequest):
|
|
| 247 |
prob_sensationalist = sens_probs[0][1].item()
|
| 248 |
is_sensationalist = prob_sensationalist >= sens_threshold
|
| 249 |
|
| 250 |
-
# Calculate confidences of the PREDICTED class
|
| 251 |
-
# If is_clickbait is True, we want prob of Clickbait (prob_clickbait)
|
| 252 |
-
# If is_clickbait is False, we want prob of NOT Clickbait (1 - prob_clickbait or prob_not_clickbait)
|
| 253 |
-
# Clickbait model: Label 0 = Clickbait
|
| 254 |
-
conf_clickbait = prob_clickbait if is_clickbait else cb_probs[0][1].item()
|
| 255 |
-
|
| 256 |
-
# Sensationalism model: Label 1 = Sensationalist
|
| 257 |
-
conf_sensationalist = prob_sensationalist if is_sensationalist else sens_probs[0][0].item()
|
| 258 |
-
|
| 259 |
return {
|
| 260 |
"title": title,
|
| 261 |
"text_snippet": text[:200] + "..." if len(text) > 200 else text,
|
| 262 |
"is_clickbait": is_clickbait,
|
| 263 |
"is_sensationalist": is_sensationalist,
|
| 264 |
-
"clickbait_conf": float(
|
| 265 |
-
"sensationalist_conf": float(
|
| 266 |
}
|
| 267 |
|
| 268 |
except Exception as e:
|
|
|
|
| 172 |
"newspaper": row.get('newspaper', 'Unknown'),
|
| 173 |
"url": row.get('article_url', '#'),
|
| 174 |
"newspaper_url": row.get('newspaper_url', '#'),
|
| 175 |
+
"is_clickbait": bool(row.get('is_clickbait', False)) if pd.notna(row.get('is_clickbait')) else None,
|
| 176 |
+
"is_sensationalist": bool(row.get('is_sensationalist', False)) if pd.notna(row.get('is_sensationalist')) else None
|
|
|
|
| 177 |
})
|
| 178 |
|
| 179 |
# Size calc
|
|
|
|
| 246 |
prob_sensationalist = sens_probs[0][1].item()
|
| 247 |
is_sensationalist = prob_sensationalist >= sens_threshold
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
return {
|
| 250 |
"title": title,
|
| 251 |
"text_snippet": text[:200] + "..." if len(text) > 200 else text,
|
| 252 |
"is_clickbait": is_clickbait,
|
| 253 |
"is_sensationalist": is_sensationalist,
|
| 254 |
+
"clickbait_conf": float(prob_clickbait), # Sending confidence of being clickbait
|
| 255 |
+
"sensationalist_conf": float(prob_sensationalist)
|
| 256 |
}
|
| 257 |
|
| 258 |
except Exception as e:
|