meruem123 commited on
Commit
63b2f79
·
verified ·
1 Parent(s): 567860d

Upload 6 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ data/Motor_Vehicle_Collisions_-_Crashes_20250430.csv filter=lfs diff=lfs merge=lfs -text
37
+ X_test_ingestion_.csv filter=lfs diff=lfs merge=lfs -text
Serious_Injury_modeling.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
X_test_ingestion_.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8de2822e32c5e4b9cb85e30983d45c93abdf16d1ed90285f8a8b64c564c2b279
3
+ size 10971517
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import pydeck as pdk
4
+ import time
5
+ import joblib
6
+
7
+ # Load your test data
8
+ X_test = pd.read_csv("/Users/shivendragupta/Desktop/ML Final Project/X_test_ingestion_.csv").rename(columns={"Unnamed: 0": "crash_id"})
9
+ X_crash = pd.read_csv("data/Motor_Vehicle_Collisions_-_Crashes_20250430.csv") # Must include 'LATITUDE', 'LONGITUDE'
10
+
11
+ # Load model
12
+ model = joblib.load("model.pkl")
13
+
14
+ # App title
15
+ st.set_page_config(layout="wide")
16
+ st.title("🚨 Real-Time Crash Reporting (Simulation)")
17
+
18
+ # Notification/alert placeholder at the very top
19
+ alert_placeholder = st.empty()
20
+
21
+ # Create layout: map on left (wider), serious crash list on right
22
+ col1, col2 = st.columns([3, 1]) # Increase map size by giving more weight
23
+
24
+ # Placeholders for dynamic content
25
+ placeholder_map = col1.empty()
26
+ placeholder_table = col1.empty()
27
+ serious_crashes_placeholder = col2.empty()
28
+
29
+ # Start button
30
+ if st.button("Start Reporting Crashes"):
31
+ crash_points = [] # For map
32
+ serious_crashes = [] # For serious crash list
33
+
34
+ for index, row in X_test.iterrows():
35
+ # Get full crash data
36
+ row_crash = X_crash.iloc[row['crash_id']]
37
+ lat = row_crash["LATITUDE"]
38
+ lon = row_crash["LONGITUDE"]
39
+
40
+ if pd.isna(lat) or pd.isna(lon):
41
+ continue
42
+
43
+ # Predict severity
44
+ severity = model.predict(row.iloc[1:].values.reshape(1, -1))[0]
45
+
46
+ # Show alert and record serious crash
47
+ if severity == 1:
48
+ alert_placeholder.error(
49
+ f"🚨 Serious Crash Detected! Location: {row_crash['BOROUGH']} on {row_crash['ON STREET NAME']} ({lat:.4f}, {lon:.4f})"
50
+ )
51
+ serious_crashes.append({
52
+ "borough": row_crash["BOROUGH"],
53
+ "street": row_crash["ON STREET NAME"],
54
+ "latitude": lat,
55
+ "longitude": lon
56
+ })
57
+ serious_crashes_df = pd.DataFrame(serious_crashes)
58
+ serious_crashes_placeholder.dataframe(serious_crashes_df)
59
+ else:
60
+ alert_placeholder.info("Monitoring for new serious crashes...")
61
+
62
+ # Add crash to map points
63
+ crash_points.append({
64
+ "lat": lat,
65
+ "lon": lon,
66
+ "severity": "Serious Injury" if severity == 1 else "Not Serious",
67
+ "color": [255, 0, 0] if severity == 1 else [0, 0, 255],
68
+ "borough": row_crash["BOROUGH"],
69
+ "street": row_crash["ON STREET NAME"]
70
+ })
71
+
72
+ df_points = pd.DataFrame(crash_points)
73
+
74
+ # PyDeck Layer
75
+ layer = pdk.Layer(
76
+ "ScatterplotLayer",
77
+ data=df_points,
78
+ get_position='[lon, lat]',
79
+ get_radius=200,
80
+ get_fill_color='color',
81
+ pickable=True
82
+ )
83
+
84
+ view_state = pdk.ViewState(latitude=40.75, longitude=-73.95, zoom=10)
85
+
86
+ # Update visuals
87
+ placeholder_map.pydeck_chart(pdk.Deck(layers=[layer], initial_view_state=view_state))
88
+ placeholder_table.dataframe(df_points)
89
+
90
+ time.sleep(5)
91
+
92
+ st.success("✅ All crash reports simulated!")
data/Motor_Vehicle_Collisions_-_Crashes_20250430.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d6cde04749a830987012f2839e193c43e41abfbd8f52616b4c0e22908d2069c1
3
+ size 458451404
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1bc6474bbcb554961c9c5167c2da91c822c9c1040363b5f870cd00c4904f885e
3
+ size 1223108
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ pydeck
4
+ scikit-learn
5
+ joblib
6
+ numpy