Spaces:
Sleeping
Sleeping
Update charts.py
Browse files
charts.py
CHANGED
|
@@ -8,9 +8,9 @@ Every public function:
|
|
| 8 |
import pandas as pd
|
| 9 |
import plotly.graph_objects as go
|
| 10 |
|
| 11 |
-
|
| 12 |
# Palette (matches app.py CSS variables)
|
| 13 |
-
|
| 14 |
BG = "rgba(0,0,0,0)"
|
| 15 |
CARD = "#13161e"
|
| 16 |
BORDER = "#1e2330"
|
|
@@ -31,9 +31,9 @@ _BASE = dict(
|
|
| 31 |
)
|
| 32 |
|
| 33 |
|
| 34 |
-
|
| 35 |
# Shared empty figure
|
| 36 |
-
|
| 37 |
|
| 38 |
def _empty(msg: str = "Run analysis to see data", height: int = 220) -> go.Figure:
|
| 39 |
fig = go.Figure()
|
|
@@ -49,9 +49,9 @@ def _score_color(v: float) -> str:
|
|
| 49 |
return GREEN if v < 0.35 else (AMBER if v < 0.65 else RED)
|
| 50 |
|
| 51 |
|
| 52 |
-
|
| 53 |
# 1. Misinformation gauge
|
| 54 |
-
|
| 55 |
|
| 56 |
def misinfo_gauge(score: float, title: str = "Misinfo Score") -> go.Figure:
|
| 57 |
try:
|
|
@@ -91,9 +91,9 @@ def misinfo_gauge(score: float, title: str = "Misinfo Score") -> go.Figure:
|
|
| 91 |
return _empty("Gauge unavailable", 230)
|
| 92 |
|
| 93 |
|
| 94 |
-
|
| 95 |
# 2. Stream-level risk bars
|
| 96 |
-
|
| 97 |
|
| 98 |
def stream_trust_bars(stream_details: dict) -> go.Figure:
|
| 99 |
try:
|
|
@@ -137,9 +137,9 @@ def stream_trust_bars(stream_details: dict) -> go.Figure:
|
|
| 137 |
return _empty("Stream bars unavailable", 230)
|
| 138 |
|
| 139 |
|
| 140 |
-
|
| 141 |
# 3. Sentiment donut
|
| 142 |
-
|
| 143 |
|
| 144 |
def sentiment_donut(sent_sum: dict) -> go.Figure:
|
| 145 |
try:
|
|
@@ -184,9 +184,9 @@ def sentiment_donut(sent_sum: dict) -> go.Figure:
|
|
| 184 |
return _empty("Donut unavailable", 230)
|
| 185 |
|
| 186 |
|
| 187 |
-
|
| 188 |
# 4. Keyword bar
|
| 189 |
-
|
| 190 |
|
| 191 |
def keyword_bar(
|
| 192 |
keywords: list,
|
|
@@ -238,9 +238,9 @@ def keyword_bar(
|
|
| 238 |
return _empty("Keyword bar unavailable", 260)
|
| 239 |
|
| 240 |
|
| 241 |
-
|
| 242 |
# 5. Sentiment timeline (scatter + rolling avg)
|
| 243 |
-
|
| 244 |
|
| 245 |
def sentiment_timeline(df: pd.DataFrame, sentiments: list) -> go.Figure:
|
| 246 |
try:
|
|
@@ -308,9 +308,9 @@ def sentiment_timeline(df: pd.DataFrame, sentiments: list) -> go.Figure:
|
|
| 308 |
return _empty("Timeline unavailable", 230)
|
| 309 |
|
| 310 |
|
| 311 |
-
|
| 312 |
# 6. Keyword sentiment comparison (diverging bar)
|
| 313 |
-
|
| 314 |
|
| 315 |
def keyword_comparison(pos_kw: list, neg_kw: list) -> go.Figure:
|
| 316 |
try:
|
|
|
|
| 8 |
import pandas as pd
|
| 9 |
import plotly.graph_objects as go
|
| 10 |
|
| 11 |
+
|
| 12 |
# Palette (matches app.py CSS variables)
|
| 13 |
+
|
| 14 |
BG = "rgba(0,0,0,0)"
|
| 15 |
CARD = "#13161e"
|
| 16 |
BORDER = "#1e2330"
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
|
| 34 |
+
|
| 35 |
# Shared empty figure
|
| 36 |
+
|
| 37 |
|
| 38 |
def _empty(msg: str = "Run analysis to see data", height: int = 220) -> go.Figure:
|
| 39 |
fig = go.Figure()
|
|
|
|
| 49 |
return GREEN if v < 0.35 else (AMBER if v < 0.65 else RED)
|
| 50 |
|
| 51 |
|
| 52 |
+
|
| 53 |
# 1. Misinformation gauge
|
| 54 |
+
|
| 55 |
|
| 56 |
def misinfo_gauge(score: float, title: str = "Misinfo Score") -> go.Figure:
|
| 57 |
try:
|
|
|
|
| 91 |
return _empty("Gauge unavailable", 230)
|
| 92 |
|
| 93 |
|
| 94 |
+
|
| 95 |
# 2. Stream-level risk bars
|
| 96 |
+
|
| 97 |
|
| 98 |
def stream_trust_bars(stream_details: dict) -> go.Figure:
|
| 99 |
try:
|
|
|
|
| 137 |
return _empty("Stream bars unavailable", 230)
|
| 138 |
|
| 139 |
|
| 140 |
+
|
| 141 |
# 3. Sentiment donut
|
| 142 |
+
|
| 143 |
|
| 144 |
def sentiment_donut(sent_sum: dict) -> go.Figure:
|
| 145 |
try:
|
|
|
|
| 184 |
return _empty("Donut unavailable", 230)
|
| 185 |
|
| 186 |
|
| 187 |
+
|
| 188 |
# 4. Keyword bar
|
| 189 |
+
|
| 190 |
|
| 191 |
def keyword_bar(
|
| 192 |
keywords: list,
|
|
|
|
| 238 |
return _empty("Keyword bar unavailable", 260)
|
| 239 |
|
| 240 |
|
| 241 |
+
|
| 242 |
# 5. Sentiment timeline (scatter + rolling avg)
|
| 243 |
+
|
| 244 |
|
| 245 |
def sentiment_timeline(df: pd.DataFrame, sentiments: list) -> go.Figure:
|
| 246 |
try:
|
|
|
|
| 308 |
return _empty("Timeline unavailable", 230)
|
| 309 |
|
| 310 |
|
| 311 |
+
|
| 312 |
# 6. Keyword sentiment comparison (diverging bar)
|
| 313 |
+
|
| 314 |
|
| 315 |
def keyword_comparison(pos_kw: list, neg_kw: list) -> go.Figure:
|
| 316 |
try:
|