Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,52 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
from datetime import datetime
|
4 |
-
|
5 |
-
# Initialize the state for the excel file name
|
6 |
-
if 'excel_file_name' not in st.session_state:
|
7 |
-
st.session_state.excel_file_name = 'combined_duplicates_removed.csv'
|
8 |
-
|
9 |
-
# Streamlit title
|
10 |
-
st.title("
|
11 |
-
|
12 |
-
# Button to update the dataset
|
13 |
-
if st.button("Update Dataset"):
|
14 |
-
st.session_state.excel_file_name = 'updated.csv'
|
15 |
-
|
16 |
-
# Get the current excel file name from session state
|
17 |
-
excel_file_name = st.session_state.excel_file_name
|
18 |
-
|
19 |
-
# Display a note to the user
|
20 |
-
st.write("Please Note, First Date must be smaller than Last date. Example: First Date = 25-08-2024 and Last Date = 28-08-2024")
|
21 |
-
|
22 |
-
# Get today's date
|
23 |
-
today = datetime.strptime(datetime.today().strftime('%d-%m-%Y'), '%d-%m-%Y')
|
24 |
-
|
25 |
-
# Input fields for date range
|
26 |
-
start = st.date_input("Enter first date", max_value=today, format="DD-MM-YYYY")
|
27 |
-
start_string = start.strftime('%d-%m-%Y')
|
28 |
-
end = st.date_input("Enter last date", max_value=today, format="DD-MM-YYYY")
|
29 |
-
end_string = end.strftime('%d-%m-%Y')
|
30 |
-
|
31 |
-
# Button to generate dataset based on date range
|
32 |
-
if st.button("Generate Dataset"):
|
33 |
-
# Read the selected excel file
|
34 |
-
df3 = pd.read_csv(excel_file_name)
|
35 |
-
|
36 |
-
# Convert 'Publish Date' column to datetime with 'day-month-year' format
|
37 |
-
df3['Publish Date'] = pd.to_datetime(df3['Publish Date'], format='%d-%m-%Y')
|
38 |
-
|
39 |
-
# Convert user input dates to datetime
|
40 |
-
start_date = pd.to_datetime(start_string, format='%d-%m-%Y')
|
41 |
-
end_date = pd.to_datetime(end_string, format='%d-%m-%Y')
|
42 |
-
|
43 |
-
# Filter rows based on the specified date range
|
44 |
-
filtered_entries = df3[(df3['Publish Date'] >= start_date) & (df3['Publish Date'] <= end_date)]
|
45 |
-
filtered_entries.reset_index(inplace=True, drop=True)
|
46 |
-
|
47 |
-
# Display the filtered data
|
48 |
-
st.dataframe(filtered_entries)
|
49 |
-
|
50 |
-
# Display selected start and end dates
|
51 |
-
st.write("Start date is:", start)
|
52 |
-
st.write("End date is:", end)
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from datetime import datetime
|
4 |
+
|
5 |
+
# Initialize the state for the excel file name
|
6 |
+
if 'excel_file_name' not in st.session_state:
|
7 |
+
st.session_state.excel_file_name = 'combined_duplicates_removed.csv'
|
8 |
+
|
9 |
+
# Streamlit title
|
10 |
+
st.title("Automated Road Accident Monitoring System")
|
11 |
+
|
12 |
+
# Button to update the dataset
|
13 |
+
if st.button("Update Dataset"):
|
14 |
+
st.session_state.excel_file_name = 'updated.csv'
|
15 |
+
|
16 |
+
# Get the current excel file name from session state
|
17 |
+
excel_file_name = st.session_state.excel_file_name
|
18 |
+
|
19 |
+
# Display a note to the user
|
20 |
+
st.write("Please Note, First Date must be smaller than Last date. Example: First Date = 25-08-2024 and Last Date = 28-08-2024")
|
21 |
+
|
22 |
+
# Get today's date
|
23 |
+
today = datetime.strptime(datetime.today().strftime('%d-%m-%Y'), '%d-%m-%Y')
|
24 |
+
|
25 |
+
# Input fields for date range
|
26 |
+
start = st.date_input("Enter first date", max_value=today, format="DD-MM-YYYY")
|
27 |
+
start_string = start.strftime('%d-%m-%Y')
|
28 |
+
end = st.date_input("Enter last date", max_value=today, format="DD-MM-YYYY")
|
29 |
+
end_string = end.strftime('%d-%m-%Y')
|
30 |
+
|
31 |
+
# Button to generate dataset based on date range
|
32 |
+
if st.button("Generate Dataset"):
|
33 |
+
# Read the selected excel file
|
34 |
+
df3 = pd.read_csv(excel_file_name)
|
35 |
+
|
36 |
+
# Convert 'Publish Date' column to datetime with 'day-month-year' format
|
37 |
+
df3['Publish Date'] = pd.to_datetime(df3['Publish Date'], format='%d-%m-%Y')
|
38 |
+
|
39 |
+
# Convert user input dates to datetime
|
40 |
+
start_date = pd.to_datetime(start_string, format='%d-%m-%Y')
|
41 |
+
end_date = pd.to_datetime(end_string, format='%d-%m-%Y')
|
42 |
+
|
43 |
+
# Filter rows based on the specified date range
|
44 |
+
filtered_entries = df3[(df3['Publish Date'] >= start_date) & (df3['Publish Date'] <= end_date)]
|
45 |
+
filtered_entries.reset_index(inplace=True, drop=True)
|
46 |
+
|
47 |
+
# Display the filtered data
|
48 |
+
st.dataframe(filtered_entries)
|
49 |
+
|
50 |
+
# Display selected start and end dates
|
51 |
+
st.write("Start date is:", start)
|
52 |
+
st.write("End date is:", end)
|