-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
134 lines (91 loc) · 3.52 KB
/
Copy pathapp.py
File metadata and controls
134 lines (91 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
# --------------------------------
# PAGE TITLE
# --------------------------------
st.title("📰 AI News Event Clustering System")
st.write(
"This dashboard displays clustered news events, "
"event timelines, summaries, and related articles."
)
# --------------------------------
# SIDEBAR
# --------------------------------
st.sidebar.title("📂 Navigation")
st.sidebar.write("AI News Event Clustering Dashboard")
st.sidebar.write("Select an event group to explore timelines, summaries, and related articles.")
# --------------------------------
# EVENT LABELS
# --------------------------------
event_labels = {
0: "Trump Campaign and Election Strategy",
1: "Hillary Clinton Controversies",
2: "Trump Media Reactions and Public Opinion",
3: "Race Politics and Black Lives Matter",
4: "Republican Support and Trump Movement"
}
# --------------------------------
# LOAD DATA
# --------------------------------
df = pd.read_csv("cleaned_news.csv")
df['date'] = pd.to_datetime(df['date'])
# --------------------------------
# SELECT EVENT
# --------------------------------
selected_cluster = st.selectbox(
"Select Event Group",
list(event_labels.keys()),
format_func=lambda x: event_labels[x]
)
# filter cluster
cluster_articles = df[df['cluster'] == selected_cluster]
# sort by date
cluster_articles = cluster_articles.sort_values(by='date')
# --------------------------------
# EVENT SUMMARY
# --------------------------------
st.header("📌 Event Summary")
summaries = {
0: "This event focused on Donald Trump’s campaign strategy, debates, immigration discussions, and political developments during the 2016 election.",
1: "This event covered controversies surrounding Hillary Clinton, including campaign criticism, public reactions, and political debates.",
2: "This event highlighted media reactions, protests, and public opinion related to Donald Trump during the election season.",
3: "This event focused on race politics, Black Lives Matter discussions, and political responses during the 2016 election.",
4: "This event included Republican support movements, anti-Trump campaigns, and political strategy discussions."
}
st.write(summaries[selected_cluster])
st.metric(
"Number of Articles",
len(cluster_articles)
)
# --------------------------------
# EVENT TIMELINE
# --------------------------------
st.header("📅 Event Evolution Timeline")
timeline_articles = cluster_articles.head(5)
for i, (_, row) in enumerate(timeline_articles.iterrows(), 1):
title = row['title'].split(" - ")[0]
st.markdown(
f"""
### 🔹 {row['date'].date()}
**Event:** {title}
"""
)
st.write("---")
search_term = st.text_input("🔍 Search Articles")
if search_term:
cluster_articles = cluster_articles[
cluster_articles['title']
.str.contains(search_term, case=False)
]
# --------------------------------
# ARTICLES INSIDE EVENT
# --------------------------------
st.header("📰 Articles Inside Event")
for i, (_, row) in enumerate(cluster_articles.iterrows(), 1):
with st.expander(f"{i}. {row['title']}"):
st.write(f"📅 Date: {row['date'].date()}")
st.write(f"🏢 Source: {row['publication']}")
# short preview
content = str(row['content'])[:300]
st.write(content + "...")