Humanize event detail explanations and make source links clickable
Browse files- public_space_app.py +33 -6
public_space_app.py
CHANGED
|
@@ -803,6 +803,29 @@ def _plain_reason_code(value: str) -> str:
|
|
| 803 |
return mapping.get(normalized, normalized.replace("_", " ").title() or "Signal")
|
| 804 |
|
| 805 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 806 |
def _edge_evidence_chips(row: Dict[str, Any]) -> list[str]:
|
| 807 |
urls = _split_pipe_values(row.get("source_urls", ""), limit=12)
|
| 808 |
reason_codes = set(_split_pipe_values(row.get("reason_codes", ""), limit=20))
|
|
@@ -1071,7 +1094,7 @@ def _relationship_detail_markdown(edges: pd.DataFrame, relationship_id: str) ->
|
|
| 1071 |
lines.extend(f"- {item}" for item in reason_codes)
|
| 1072 |
if urls:
|
| 1073 |
lines.extend(["", "#### Example published source URLs", ""])
|
| 1074 |
-
lines.extend(f"- {item}" for item in urls)
|
| 1075 |
lines.extend(
|
| 1076 |
[
|
| 1077 |
"",
|
|
@@ -1415,7 +1438,7 @@ def _event_detail(events: pd.DataFrame, provenance: pd.DataFrame, event_id: str)
|
|
| 1415 |
lines.append(f"- Score label: `{score_label}`")
|
| 1416 |
confidence_bucket = str(event_row.get("confidence_bucket") or "").strip()
|
| 1417 |
if confidence_bucket:
|
| 1418 |
-
lines.append(f"- Confidence
|
| 1419 |
if issuer_raw:
|
| 1420 |
lines.append(f"- Issuer or subject: `{issuer_raw}`")
|
| 1421 |
if sector:
|
|
@@ -1433,10 +1456,10 @@ def _event_detail(events: pd.DataFrame, provenance: pd.DataFrame, event_id: str)
|
|
| 1433 |
lines.extend(f"- `{item}`" for item in reason_codes[:8])
|
| 1434 |
if missing_to_strengthen:
|
| 1435 |
lines.extend(["", "#### What would strengthen it", ""])
|
| 1436 |
-
lines.extend(f"-
|
| 1437 |
if source_urls:
|
| 1438 |
lines.extend(["", "#### Example source URLs", ""])
|
| 1439 |
-
lines.extend(f"- {item}" for item in source_urls)
|
| 1440 |
if sha_values:
|
| 1441 |
lines.extend(["", "#### Example SHA-256 values", ""])
|
| 1442 |
lines.extend(f"- `{item}`" for item in sha_values)
|
|
@@ -1734,9 +1757,13 @@ def build_app(copy_path: str | Path):
|
|
| 1734 |
table_html = _table_html(
|
| 1735 |
prov_rows,
|
| 1736 |
empty_message="No provenance rows are attached to this released event row.",
|
| 1737 |
-
note="Scroll sideways to inspect all provenance columns and URLs.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1738 |
)
|
| 1739 |
-
return detail_md, table_html
|
| 1740 |
|
| 1741 |
event_id.change(_event_detail_view, [gr.State(events), gr.State(provenance), event_id], [event_detail_md, event_detail_df])
|
| 1742 |
app.load(_event_detail_view, [gr.State(events), gr.State(provenance), event_id], [event_detail_md, event_detail_df])
|
|
|
|
| 803 |
return mapping.get(normalized, normalized.replace("_", " ").title() or "Signal")
|
| 804 |
|
| 805 |
|
| 806 |
+
def _plain_strengthener(value: str) -> str:
|
| 807 |
+
normalized = str(value or "").strip()
|
| 808 |
+
mapping = {
|
| 809 |
+
"bill_sector_mapping_weak": "Requires stronger correlation between the trade window and related bill subject matter.",
|
| 810 |
+
"donor_industry_mapping_weak": "Missing granular donor industry classification.",
|
| 811 |
+
"committee_history_missing": "Committee history is missing or incomplete for this row.",
|
| 812 |
+
"lobbying_issue_mapping_weak": "Requires clearer mapping between lobbying issue tags and the policy area in this row.",
|
| 813 |
+
"recipient_identity_ambiguous": "The recipient identity needs a cleaner match before this can be treated as a stronger link.",
|
| 814 |
+
"insufficient_official_support": "Needs more direct official-record support before this can be treated as a stronger link.",
|
| 815 |
+
"vote_history_missing": "Vote history is missing or incomplete for this row.",
|
| 816 |
+
}
|
| 817 |
+
return mapping.get(normalized, normalized.replace("_", " ").capitalize() or "Additional support is needed.")
|
| 818 |
+
|
| 819 |
+
|
| 820 |
+
def _confidence_label(value: str) -> str:
|
| 821 |
+
normalized = str(value or "").strip().lower()
|
| 822 |
+
return {
|
| 823 |
+
"high": "🟢 High confidence",
|
| 824 |
+
"medium": "🟡 Medium confidence",
|
| 825 |
+
"low": "🟠 Lower confidence",
|
| 826 |
+
}.get(normalized, normalized.title() or "Confidence not labeled")
|
| 827 |
+
|
| 828 |
+
|
| 829 |
def _edge_evidence_chips(row: Dict[str, Any]) -> list[str]:
|
| 830 |
urls = _split_pipe_values(row.get("source_urls", ""), limit=12)
|
| 831 |
reason_codes = set(_split_pipe_values(row.get("reason_codes", ""), limit=20))
|
|
|
|
| 1094 |
lines.extend(f"- {item}" for item in reason_codes)
|
| 1095 |
if urls:
|
| 1096 |
lines.extend(["", "#### Example published source URLs", ""])
|
| 1097 |
+
lines.extend(f"- [{item}]({item})" for item in urls)
|
| 1098 |
lines.extend(
|
| 1099 |
[
|
| 1100 |
"",
|
|
|
|
| 1438 |
lines.append(f"- Score label: `{score_label}`")
|
| 1439 |
confidence_bucket = str(event_row.get("confidence_bucket") or "").strip()
|
| 1440 |
if confidence_bucket:
|
| 1441 |
+
lines.append(f"- Confidence level: {_confidence_label(confidence_bucket)}")
|
| 1442 |
if issuer_raw:
|
| 1443 |
lines.append(f"- Issuer or subject: `{issuer_raw}`")
|
| 1444 |
if sector:
|
|
|
|
| 1456 |
lines.extend(f"- `{item}`" for item in reason_codes[:8])
|
| 1457 |
if missing_to_strengthen:
|
| 1458 |
lines.extend(["", "#### What would strengthen it", ""])
|
| 1459 |
+
lines.extend(f"- {_plain_strengthener(item)}" for item in missing_to_strengthen[:8])
|
| 1460 |
if source_urls:
|
| 1461 |
lines.extend(["", "#### Example source URLs", ""])
|
| 1462 |
+
lines.extend(f"- [{item}]({item})" for item in source_urls)
|
| 1463 |
if sha_values:
|
| 1464 |
lines.extend(["", "#### Example SHA-256 values", ""])
|
| 1465 |
lines.extend(f"- `{item}`" for item in sha_values)
|
|
|
|
| 1757 |
table_html = _table_html(
|
| 1758 |
prov_rows,
|
| 1759 |
empty_message="No provenance rows are attached to this released event row.",
|
| 1760 |
+
note="Technical data table. Scroll sideways to inspect all provenance columns and URLs.",
|
| 1761 |
+
)
|
| 1762 |
+
return detail_md, (
|
| 1763 |
+
'<div class="panel-note"><strong>Technical data table</strong><br>'
|
| 1764 |
+
'This section is for power users who want the raw released provenance rows behind the summary above.</div>'
|
| 1765 |
+
+ table_html
|
| 1766 |
)
|
|
|
|
| 1767 |
|
| 1768 |
event_id.change(_event_detail_view, [gr.State(events), gr.State(provenance), event_id], [event_detail_md, event_detail_df])
|
| 1769 |
app.load(_event_detail_view, [gr.State(events), gr.State(provenance), event_id], [event_detail_md, event_detail_df])
|