abhicodes commited on
Commit
6f2f7b4
·
1 Parent(s): cb13fc1

Update app.txt

Browse files
Files changed (1) hide show
  1. app.txt +78 -98
app.txt CHANGED
@@ -1,124 +1,104 @@
1
  import gradio as gr
2
  import joblib
3
- import pandas as pd
4
 
5
  # Load the model
6
- model = joblib.load('accident_prediction_model_Final.m5')
7
-
8
- # Load the encoder
9
- encoder = joblib.load('encoder.pkl')
10
-
11
- # Define classes for accident prediction
12
- classes = ["No", "Yes"]
13
 
14
  # Create the inputs list with dropdown menus and sliders
15
  inputs = [
16
  gr.Dropdown(
17
- choices=['Sunny/Clear', 'Rainy', 'Hail/Sleet', 'Foggy/Misty', 'Others'],
18
- label="Weather Conditions"
19
- ),
20
- gr.Dropdown(
21
- choices=['Pedestrian', 'Bicycles', 'Two Wheelers', 'Auto Rickshaws', 'Cars, Taxis, Vans & LMV', 'Trucks, Lorries', 'Buses', 'Non-motorized Vehicles', 'Others'],
22
- label="Impact Type"
23
- ),
24
- gr.Dropdown(
25
- choices=['Speeding', 'Jumping Red Light', 'Distracted Driving', 'Drunk Driving', 'Other'],
26
- label="Traffic Violations"
27
  ),
28
  gr.Dropdown(
29
- choices=['Straight Road', 'Curved Road', 'Bridge', 'Culvert', 'Pot Holes', 'Steep Grade', 'Ongoing Road Works/Under Construction', 'Others'],
30
- label="Road Features"
 
31
  ),
32
- gr.Dropdown(
33
- choices=['T-Junction', 'Y-Junction', 'Four arm Junction', 'Staggered Junction', 'Round about Junction', 'Others'],
34
- label="Junction Types"
35
- ),
36
- gr.Dropdown(
37
- choices=['Traffic Light Signal', 'Police Controlled', 'Stop Sign', 'Flashing Signal/Blinker', 'Uncontrolled', 'Others'],
38
- label="Traffic Controls"
39
- ),
40
- gr.Dropdown(
41
- choices=['morning', 'afternoon', 'evening', 'night'],
42
- label="Time of Day"
43
- ),
44
- gr.Dropdown(
45
- choices=['13-17', '18-25', '26-40', '41-60', '60-80', '80 above'],
46
- label="Age Group"
47
- ),
48
- gr.Dropdown(
49
- choices=['Killed', 'Grievously Injured', 'Minor Injury'],
50
- label="Injury Type"
51
- ),
52
- gr.Dropdown(
53
- choices=['Yes', 'No'],
54
- label="Safety Features"
55
- ),
56
- gr.Slider(minimum=-90, maximum=90, label="Latitude"),
57
- gr.Slider(minimum=-180, maximum=180, label="Longitude"),
58
- gr.Slider(minimum=1, maximum=10, step= 1, label="Person Count"),
59
  ]
60
 
61
- # Define output label
62
- output_label = gr.Label(num_top_classes=4)
63
 
64
  # Create a function to make predictions
65
  def predict_accident(
66
- weather_conditions,
67
- impact_type,
68
- traffic_violations,
69
- road_features,
70
- junction_types,
71
- traffic_controls,
72
- time_day,
73
- age_group,
74
- injury,
75
- safety_features,
76
- Latitude,
77
- Longitude,
78
- person_count
79
  ):
80
- data = {
81
- 'selectedWeatherCondition': weather_conditions,
82
- 'selectedImpactType': impact_type,
83
- 'selectedTrafficViolationType': traffic_violations,
84
- 'selectedRoadFeaturesType': road_features,
85
- 'selectedRoadJunctionType': junction_types,
86
- 'selectedTrafficControl': traffic_controls,
87
- 'selectedTimeOfDay': time_day,
88
- 'selectedAge': age_group,
89
- 'selectedInjuryType': injury,
90
- 'selectedSafetyFeature': safety_features,
91
- 'Latitude': Latitude,
92
- 'Longitude': Longitude,
93
- 'personCount': person_count
94
- }
95
-
96
- num_input = {'Latitude': data['Latitude'], 'Longitude': data['Longitude'], 'person_count': data['personCount']}
97
- cat_input = {'weather_conditions': data['selectedWeatherCondition'], 'impact_type': data['selectedImpactType'],
98
- 'traffic_voilations': data['selectedTrafficViolationType'],
99
- 'road_features': data['selectedRoadFeaturesType'],
100
- 'junction_types': data['selectedRoadJunctionType'],
101
- 'traffic_controls': data['selectedTrafficControl'], 'time_day': data['selectedTimeOfDay'],
102
- 'age_group': data['selectedAge'], 'safety_features': data['selectedSafetyFeature'],
103
- 'injury': data['selectedInjuryType']}
104
-
105
- input_df = pd.DataFrame([cat_input])
106
 
107
- encoded_input = encoder['encoder'].transform(input_df)
108
- encoded_input_df = pd.DataFrame(encoded_input, columns=encoder['encoded_columns'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
- num_df = pd.DataFrame([num_input])
111
- input_with_coords = pd.concat([num_df, encoded_input_df], axis=1)
 
112
 
113
- # Make a prediction using the trained model
114
- prediction = model.predict(input_with_coords)
115
-
116
- label = f"Accident Prediction: {classes[int(prediction[0])]}"
117
  return label
118
 
 
119
  # Create the Gradio interface
120
- title = "Accident Prediction"
121
- description = "Predict the severity of an accident based on input features."
122
  output_label = [gr.Label(num_top_classes=4)]
123
  gr.Interface(
124
  fn=predict_accident,
 
1
  import gradio as gr
2
  import joblib
3
+ import numpy as np
4
 
5
  # Load the model
6
+ model = joblib.load('cricket_score_prediction_model.pkl')
 
 
 
 
 
 
7
 
8
  # Create the inputs list with dropdown menus and sliders
9
  inputs = [
10
  gr.Dropdown(
11
+ choices=['Afghanistan', 'Australia', 'Bangladesh', 'England', 'India', 'Ireland', 'New Zealand', 'Pakistan',
12
+ 'South Africa', 'Sri Lanka', 'West Indies', 'Zimbabwe'],
13
+ label="Batting Team"
 
 
 
 
 
 
 
14
  ),
15
  gr.Dropdown(
16
+ choices=['Afghanistan', 'Australia', 'Bangladesh', 'England', 'India', 'Ireland', 'New Zealand', 'Pakistan',
17
+ 'South Africa', 'Sri Lanka', 'West Indies', 'Zimbabwe'],
18
+ label="Bowling Team"
19
  ),
20
+ gr.Slider(minimum=0, maximum=400, step=1, label="Total Runs"),
21
+ gr.Slider(minimum=0, maximum=11, step=1, label="Total Wickets"),
22
+ gr.Slider(minimum=0.0, maximum=19.6, step=0.1, label="Overs"),
23
+ gr.Slider(minimum=0, maximum=200, step=1, label="Runs last 5 overs"),
24
+ gr.Slider(minimum=0, maximum=11,step=1, label="Wickets last 5 overs"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  ]
26
 
 
 
27
 
28
  # Create a function to make predictions
29
  def predict_accident(
30
+ batting_team,
31
+ bowling_team,
32
+ total_runs,
33
+ total_wickets,
34
+ overs,
35
+ runs_last_5_overs,
36
+ wickets_last_5_overs
 
 
 
 
 
 
37
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
+ prediction_array = []
40
+ # Batting Team
41
+ if batting_team == 'Afghanistan':
42
+ prediction_array = prediction_array + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
43
+ elif batting_team == 'Australia':
44
+ prediction_array = prediction_array + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
45
+ elif batting_team == 'Bangladesh':
46
+ prediction_array = prediction_array + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
47
+ elif batting_team == 'England':
48
+ prediction_array = prediction_array + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
49
+ elif batting_team == 'India':
50
+ prediction_array = prediction_array + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
51
+ elif batting_team == 'Ireland':
52
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
53
+ elif batting_team == 'New Zealand':
54
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
55
+ elif batting_team == 'Pakistan':
56
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
57
+ elif batting_team == 'South Africa':
58
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
59
+ elif batting_team == 'Sri Lanka':
60
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
61
+ elif batting_team == 'West Indies':
62
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
63
+ elif batting_team == 'Zimbabwe':
64
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
65
+ # Bowling Team
66
+ if bowling_team == 'Afghanistan':
67
+ prediction_array = prediction_array + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
68
+ elif bowling_team == 'Australia':
69
+ prediction_array = prediction_array + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
70
+ elif bowling_team == 'Bangladesh':
71
+ prediction_array = prediction_array + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
72
+ elif bowling_team == 'England':
73
+ prediction_array = prediction_array + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
74
+ elif bowling_team == 'India':
75
+ prediction_array = prediction_array + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
76
+ elif bowling_team == 'Ireland':
77
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
78
+ elif bowling_team == 'New Zealand':
79
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
80
+ elif bowling_team == 'Pakistan':
81
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
82
+ elif bowling_team == 'South Africa':
83
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
84
+ elif bowling_team == 'Sri Lanka':
85
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
86
+ elif bowling_team == 'West Indies':
87
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
88
+ elif bowling_team == 'Zimbabwe':
89
+ prediction_array = prediction_array + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
90
 
91
+ prediction_array = prediction_array + [total_runs, total_wickets, overs, runs_last_5_overs, wickets_last_5_overs]
92
+ prediction_array = np.array([prediction_array])
93
+ prediction = model.predict(prediction_array)
94
 
95
+ label = f"Score Prediction: {(prediction[0])}"
 
 
 
96
  return label
97
 
98
+
99
  # Create the Gradio interface
100
+ title = "T20i Score Prediction"
101
+ description = "Predict the score of a T20i match."
102
  output_label = [gr.Label(num_top_classes=4)]
103
  gr.Interface(
104
  fn=predict_accident,