Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
import pandas as pd
|
2 |
import streamlit as st
|
3 |
from datasets import load_dataset
|
|
|
4 |
|
5 |
|
6 |
# Load data
|
7 |
@st.cache_data # Cache data for performance improvement
|
8 |
-
def load_data():
|
9 |
-
dataset = load_dataset("santhosh/day_in_history",
|
10 |
df = pd.DataFrame(dataset)
|
11 |
return df
|
12 |
|
@@ -36,35 +37,49 @@ def process_date(day, month, year=None):
|
|
36 |
else:
|
37 |
return [f"No data found for selected date {year} {month} {day}"]
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
def main():
|
41 |
-
df = load_data()
|
42 |
# Page title and header
|
43 |
st.title("Day in History")
|
44 |
with st.form("my_form"):
|
45 |
st.header("Select a date")
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
col1, col2, col3 = st.columns(3)
|
47 |
# Datepicker
|
48 |
with col1:
|
49 |
-
selected_day = st.selectbox(
|
|
|
|
|
50 |
with col2:
|
51 |
selected_month = st.selectbox(
|
52 |
"Select Month",
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
"March",
|
57 |
-
"April",
|
58 |
-
"May",
|
59 |
-
"June",
|
60 |
-
"July",
|
61 |
-
"August",
|
62 |
-
"September",
|
63 |
-
"October",
|
64 |
-
"November",
|
65 |
-
"December",
|
66 |
-
],
|
67 |
-
index=7,
|
68 |
)
|
69 |
with col3:
|
70 |
selected_year = st.number_input(
|
@@ -72,15 +87,17 @@ def main():
|
|
72 |
)
|
73 |
submitted = st.form_submit_button("Submit")
|
74 |
if submitted:
|
|
|
75 |
# Process data based on selected date
|
76 |
if selected_year is None or selected_year == "":
|
77 |
filtered_data = df[
|
78 |
-
(df["month"] == selected_month
|
|
|
79 |
]
|
80 |
else:
|
81 |
filtered_data = df[
|
82 |
(df["year"] == int(selected_year))
|
83 |
-
& (df["month"] == selected_month)
|
84 |
& (df["day"] == int(selected_day))
|
85 |
]
|
86 |
|
@@ -90,7 +107,9 @@ def main():
|
|
90 |
|
91 |
for index, row in filtered_data.iterrows():
|
92 |
container = st.container(border=True)
|
93 |
-
container.subheader(
|
|
|
|
|
94 |
container.markdown(
|
95 |
f"{row['event_description']}", unsafe_allow_html=True
|
96 |
)
|
|
|
1 |
import pandas as pd
|
2 |
import streamlit as st
|
3 |
from datasets import load_dataset
|
4 |
+
from datetime import datetime
|
5 |
|
6 |
|
7 |
# Load data
|
8 |
@st.cache_data # Cache data for performance improvement
|
9 |
+
def load_data(language="en"):
|
10 |
+
dataset = load_dataset("santhosh/day_in_history", language, split="train")
|
11 |
df = pd.DataFrame(dataset)
|
12 |
return df
|
13 |
|
|
|
37 |
else:
|
38 |
return [f"No data found for selected date {year} {month} {day}"]
|
39 |
|
40 |
+
supported_languages = {
|
41 |
+
"en": "English",
|
42 |
+
"ml": "Malayalam",
|
43 |
+
}
|
44 |
+
MONTHS = [
|
45 |
+
"January",
|
46 |
+
"February",
|
47 |
+
"March",
|
48 |
+
"April",
|
49 |
+
"May",
|
50 |
+
"June",
|
51 |
+
"July",
|
52 |
+
"August",
|
53 |
+
"September",
|
54 |
+
"October",
|
55 |
+
"November",
|
56 |
+
"December",
|
57 |
+
]
|
58 |
+
|
59 |
|
60 |
def main():
|
|
|
61 |
# Page title and header
|
62 |
st.title("Day in History")
|
63 |
with st.form("my_form"):
|
64 |
st.header("Select a date")
|
65 |
+
selected_language = st.selectbox(
|
66 |
+
"Select language",
|
67 |
+
supported_languages.keys(),
|
68 |
+
format_func=lambda x: supported_languages[x],
|
69 |
+
index=0,
|
70 |
+
)
|
71 |
col1, col2, col3 = st.columns(3)
|
72 |
# Datepicker
|
73 |
with col1:
|
74 |
+
selected_day = st.selectbox(
|
75 |
+
"Select Day", range(1, 32), index=datetime.now().day - 1
|
76 |
+
)
|
77 |
with col2:
|
78 |
selected_month = st.selectbox(
|
79 |
"Select Month",
|
80 |
+
range(0, 12),
|
81 |
+
format_func=lambda x: MONTHS[x],
|
82 |
+
index=datetime.now().month - 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
)
|
84 |
with col3:
|
85 |
selected_year = st.number_input(
|
|
|
87 |
)
|
88 |
submitted = st.form_submit_button("Submit")
|
89 |
if submitted:
|
90 |
+
df = load_data(selected_language)
|
91 |
# Process data based on selected date
|
92 |
if selected_year is None or selected_year == "":
|
93 |
filtered_data = df[
|
94 |
+
(df["month"] == int(selected_month + 1))
|
95 |
+
& (df["day"] == int(selected_day))
|
96 |
]
|
97 |
else:
|
98 |
filtered_data = df[
|
99 |
(df["year"] == int(selected_year))
|
100 |
+
& (df["month"] == selected_month + 1)
|
101 |
& (df["day"] == int(selected_day))
|
102 |
]
|
103 |
|
|
|
107 |
|
108 |
for index, row in filtered_data.iterrows():
|
109 |
container = st.container(border=True)
|
110 |
+
container.subheader(
|
111 |
+
f"{row['year']} {MONTHS[row['month']-1]} {row['day']}"
|
112 |
+
)
|
113 |
container.markdown(
|
114 |
f"{row['event_description']}", unsafe_allow_html=True
|
115 |
)
|