anubha-ml commited on
Commit
16c01e6
Β·
verified Β·
1 Parent(s): f65cc88

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +27 -13
  2. app.py +152 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,27 @@
1
- ---
2
- title: Accident Predictor
3
- emoji: πŸŒ–
4
- colorFrom: red
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 6.1.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Accident Severity Predictor
3
+ emoji: πŸš—
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 4.0.0
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ # πŸš— Accident Severity Predictor
13
+
14
+ A simple AI tool to predict accident severity based on driving conditions.
15
+
16
+ ## How to Use:
17
+ 1. Adjust the sliders and dropdowns
18
+ 2. Click "Predict Severity"
19
+ 3. View the predicted risk level
20
+
21
+ ## Features:
22
+ - Real-time prediction
23
+ - Multiple risk factors
24
+ - Safety recommendations
25
+ - Example scenarios
26
+
27
+ Made with ❀️ using Gradio
app.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+
5
+ # Simple prediction function
6
+ def predict_accident(
7
+ speed, vehicles, age, hour,
8
+ weather, road, vehicle_type
9
+ ):
10
+ """Simple prediction logic - you'll replace this later"""
11
+
12
+ # Simple risk calculation
13
+ risk_score = 0
14
+
15
+ # Add risk based on speed
16
+ if speed > 80:
17
+ risk_score += 30
18
+ elif speed > 60:
19
+ risk_score += 15
20
+
21
+ # Add risk based on weather
22
+ if weather in ["Rain", "Heavy Rain", "Storm"]:
23
+ risk_score += 25
24
+
25
+ # Add risk based on road condition
26
+ if road in ["Wet", "Slippery"]:
27
+ risk_score += 20
28
+
29
+ # Add risk based on vehicle type
30
+ if vehicle_type in ["Motorcycle", "Bicycle"]:
31
+ risk_score += 25
32
+
33
+ # Add risk based on time
34
+ if hour >= 20 or hour <= 6:
35
+ risk_score += 15
36
+
37
+ # Determine severity
38
+ if risk_score > 60:
39
+ severity = "FATAL 🚨"
40
+ color = "red"
41
+ elif risk_score > 40:
42
+ severity = "SERIOUS ⚠️"
43
+ color = "orange"
44
+ else:
45
+ severity = "MINOR βœ…"
46
+ color = "green"
47
+
48
+ # Create result HTML
49
+ result_html = f"""
50
+ <div style="padding: 20px; background-color: #f8f9fa; border-radius: 10px; border-left: 5px solid {color};">
51
+ <h2 style="color: {color};">Predicted Severity: {severity}</h2>
52
+ <h3>Risk Score: {risk_score}/100</h3>
53
+
54
+ <h4>πŸ“‹ Input Summary:</h4>
55
+ <ul>
56
+ <li>Speed: {speed} km/h</li>
57
+ <li>Vehicles: {vehicles}</li>
58
+ <li>Driver Age: {age} years</li>
59
+ <li>Time: {hour}:00 hours</li>
60
+ <li>Weather: {weather}</li>
61
+ <li>Road: {road}</li>
62
+ <li>Vehicle: {vehicle_type}</li>
63
+ </ul>
64
+
65
+ <h4>πŸ’‘ Safety Tips:</h4>
66
+ <ul>
67
+ <li>{"🚨 REDUCE SPEED IMMEDIATELY!" if risk_score > 60 else "⚠️ Drive with caution" if risk_score > 40 else "βœ… Safe conditions"}</li>
68
+ <li>Keep safe distance from other vehicles</li>
69
+ <li>Stay alert to changing conditions</li>
70
+ </ul>
71
+ </div>
72
+ """
73
+
74
+ return result_html, risk_score
75
+
76
+ # Create the UI
77
+ with gr.Blocks(title="Accident Predictor", theme=gr.themes.Soft()) as demo:
78
+
79
+ # Title
80
+ gr.Markdown("# πŸš— Accident Severity Predictor")
81
+ gr.Markdown("Enter details below to predict accident severity")
82
+
83
+ # Input Section
84
+ with gr.Row():
85
+ with gr.Column():
86
+ speed = gr.Slider(20, 120, value=60, label="Speed (km/h)")
87
+ vehicles = gr.Slider(1, 10, value=2, label="Number of Vehicles")
88
+ age = gr.Slider(18, 80, value=35, label="Driver Age")
89
+ hour = gr.Slider(0, 23, value=14, label="Time of Day (Hour)")
90
+
91
+ with gr.Column():
92
+ weather = gr.Dropdown(
93
+ ["Clear", "Cloudy", "Rain", "Heavy Rain", "Fog", "Storm"],
94
+ value="Clear",
95
+ label="Weather"
96
+ )
97
+ road = gr.Dropdown(
98
+ ["Dry", "Wet", "Slippery", "Damaged", "Construction"],
99
+ value="Dry",
100
+ label="Road Condition"
101
+ )
102
+ vehicle_type = gr.Dropdown(
103
+ ["Car", "Truck", "Bus", "Motorcycle", "Bicycle"],
104
+ value="Car",
105
+ label="Vehicle Type"
106
+ )
107
+
108
+ # Buttons
109
+ predict_btn = gr.Button("🚦 Predict Severity", variant="primary")
110
+
111
+ # Output Section
112
+ with gr.Row():
113
+ output_html = gr.HTML(label="Prediction Result")
114
+ risk_gauge = gr.Number(label="Risk Score (0-100)")
115
+
116
+ # Connect button to function
117
+ predict_btn.click(
118
+ fn=predict_accident,
119
+ inputs=[speed, vehicles, age, hour, weather, road, vehicle_type],
120
+ outputs=[output_html, risk_gauge]
121
+ )
122
+
123
+ # Examples Section
124
+ gr.Markdown("### 🎯 Try These Examples:")
125
+
126
+ with gr.Row():
127
+ high_risk_btn = gr.Button("High Risk Scenario")
128
+ med_risk_btn = gr.Button("Medium Risk Scenario")
129
+ low_risk_btn = gr.Button("Low Risk Scenario")
130
+
131
+ # Example functions
132
+ def set_high_risk():
133
+ return [120, 3, 22, 22, "Heavy Rain", "Slippery", "Motorcycle"], None
134
+
135
+ def set_med_risk():
136
+ return [80, 2, 35, 10, "Rain", "Wet", "Car"], None
137
+
138
+ def set_low_risk():
139
+ return [40, 1, 45, 14, "Clear", "Dry", "Car"], None
140
+
141
+ # Connect example buttons
142
+ high_risk_btn.click(set_high_risk, outputs=[speed, vehicles, age, hour, weather, road, vehicle_type, output_html])
143
+ med_risk_btn.click(set_med_risk, outputs=[speed, vehicles, age, hour, weather, road, vehicle_type, output_html])
144
+ low_risk_btn.click(set_low_risk, outputs=[speed, vehicles, age, hour, weather, road, vehicle_type, output_html])
145
+
146
+ # Footer
147
+ gr.Markdown("---")
148
+ gr.Markdown("**Note:** This is a demo. Always drive safely!")
149
+
150
+ # Launch the app
151
+ if __name__ == "__main__":
152
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio>=4.0.0
2
+ pandas>=1.5.0
3
+ numpy>=1.24.0