BAMS / app.py
Thamed-Chowdhury's picture
Update app.py
d7a62b6 verified
raw
history blame
1.93 kB
import streamlit as st
import pandas as pd
from datetime import datetime
# Initialize the state for the excel file name
if 'excel_file_name' not in st.session_state:
st.session_state.excel_file_name = 'combined_duplicates_removed.csv'
# Streamlit title
st.title("Automated Road Accident Monitoring System")
# Button to update the dataset
if st.button("Update Dataset"):
st.session_state.excel_file_name = 'updated.csv'
# Get the current excel file name from session state
excel_file_name = st.session_state.excel_file_name
# Display a note to the user
st.write("Please Note, First Date must be smaller than Last date. Example: First Date = 25-08-2024 and Last Date = 28-08-2024")
# Get today's date
today = datetime.strptime(datetime.today().strftime('%d-%m-%Y'), '%d-%m-%Y')
# Input fields for date range
start = st.date_input("Enter first date", max_value=today, format="DD-MM-YYYY")
start_string = start.strftime('%d-%m-%Y')
end = st.date_input("Enter last date", max_value=today, format="DD-MM-YYYY")
end_string = end.strftime('%d-%m-%Y')
# Button to generate dataset based on date range
if st.button("Generate Dataset"):
# Read the selected excel file
df3 = pd.read_csv(excel_file_name)
# Convert 'Publish Date' column to datetime with 'day-month-year' format
df3['Publish Date'] = pd.to_datetime(df3['Publish Date'], format='%d-%m-%Y')
# Convert user input dates to datetime
start_date = pd.to_datetime(start_string, format='%d-%m-%Y')
end_date = pd.to_datetime(end_string, format='%d-%m-%Y')
# Filter rows based on the specified date range
filtered_entries = df3[(df3['Publish Date'] >= start_date) & (df3['Publish Date'] <= end_date)]
filtered_entries.reset_index(inplace=True, drop=True)
# Display the filtered data
st.dataframe(filtered_entries)
# Display selected start and end dates
st.write("Start date is:", start)
st.write("End date is:", end)