Aaleia's picture
Update app.py
27a0563 verified
raw
history blame
2.07 kB
import streamlit as st
import numpy as np
import pandas as pd
from sodapy import Socrata
from model import predict, encode
if 'sample_data' not in st.session_state:
client = Socrata("data.cityofnewyork.us", None)
query = "INCIDENT_DATETIME >= '2024-03-01T00:00:00' AND INCIDENT_DATETIME < '2024-04-01T00:00:00'"
results = client.get("76xm-jjuj", where=query, limit=100)
data = pd.DataFrame.from_records(results)
data.columns = data.columns.str.upper()
data.dropna(inplace=True)
st.session_state.sample_data = data
sample_data = st.session_state.sample_data
st.title('EMS Call Classifier')
st.write("This project aims to improve the accuracy of predicting the nature of emergency calls in NYC, thereby improving emergency response times. It utilizes historical EMS dispatch data and real-time weather conditions to predict call types. The project's ultimate goal is to get New Yorkers the help they need even faster.")
st.header('The Data')
st.write('Provided through the NYC Open Data.')
t1, t2 = st.tabs(['EMS Incident Dispatch', 'Weather'])
t1.write("The EMS Incident Dispatch Data is generated by the EMS Computer Aided Dispatch System, and covers information about the incident as it relates to the assignment of resources and the Fire Department’s response to the emergency.")
t2.write("The Weather Data comes from...")
t1.subheader('Sample of First 100 Incidents from March 2024')
t1.dataframe(sample_data, use_container_width=True)
st.header("Analysis")
st.write("A visualization of an insight we gained from exploring and analyzing the data.")
selected = st.slider("Choose a row:", 0, sample_data.shape[0]-1, 0)
if 'selected' not in st.session_state or st.session_state.selected != selected:
row = encode(sample_data.iloc[selected])
c1, c2 = st.columns(2)
c1.dataframe(row)
c2.write("Correct Type:")
c2.dataframe({"FINAL_CALL_TYPE": sample_data.iloc[selected].FINAL_CALL_TYPE})
predicted_label = predict(row)
c2.write("Predicted Type:")
c2.dataframe({"PREDICTED_CALL_TYPE": predicted_label})
st.session_state.selected = selected