santhosh commited on
Commit
fa12a52
·
verified ·
1 Parent(s): 76d2b9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -3
app.py CHANGED
@@ -1,5 +1,5 @@
1
- import streamlit as st
2
  import pandas as pd
 
3
  from datasets import load_dataset
4
 
5
 
@@ -10,12 +10,39 @@ def load_data():
10
  df = pd.DataFrame(dataset)
11
  return df
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  def main():
14
  df = load_data()
15
  # Page title and header
16
  st.title("Day in History")
17
  with st.form("my_form"):
18
- st.header("Select a date to view results")
19
  col1, col2, col3 = st.columns(3)
20
  # Datepicker
21
  with col1:
@@ -63,7 +90,7 @@ def main():
63
 
64
  for index, row in filtered_data.iterrows():
65
  container = st.container(border=True)
66
- container.title(f"{row['year']} {row['month']} {row['day']}")
67
  container.markdown(
68
  f"{row['event_description']}", unsafe_allow_html=True
69
  )
 
 
1
  import pandas as pd
2
+ import streamlit as st
3
  from datasets import load_dataset
4
 
5
 
 
10
  df = pd.DataFrame(dataset)
11
  return df
12
 
13
+
14
+ # Function to process user input (date) and return description and reference
15
+ def process_date(day, month, year=None):
16
+ # Filter data based on selected date
17
+ if year is None or year == "":
18
+ filtered_data = df[(df["month"] == month) & (df["day"] == int(day))]
19
+ else:
20
+ filtered_data = df[
21
+ (df["year"] == int(year)) & (df["month"] == month) & (df["day"] == int(day))
22
+ ]
23
+
24
+ if not filtered_data.empty:
25
+ # Prepare empty lists to store descriptions and references
26
+ descriptions = []
27
+ references = []
28
+
29
+ # Loop through filtered data and append descriptions and references
30
+ for index, row in filtered_data.iterrows():
31
+ descriptions.append(row["event_description"])
32
+ references.append(row["reference"])
33
+
34
+ # Return lists of descriptions and references
35
+ return descriptions
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:
 
90
 
91
  for index, row in filtered_data.iterrows():
92
  container = st.container(border=True)
93
+ container.subheader(f"{row['year']} {row['month']} {row['day']}")
94
  container.markdown(
95
  f"{row['event_description']}", unsafe_allow_html=True
96
  )