correct app
Browse files- app.py +64 -4
- joblib/qod_encoder_CA.joblib +3 -0
- joblib/rf_classifier_CA.joblib +3 -0
app.py
CHANGED
|
@@ -1,7 +1,67 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
import sklearn
|
| 5 |
+
import pandas as pd
|
| 6 |
|
| 7 |
+
model = joblib.load("joblib/rf_classifier_CA.joblib")
|
| 8 |
+
qod_encoder = joblib.load("joblib/qod_encoder_CA.joblib")
|
| 9 |
|
| 10 |
+
def predict(pressure, temperature, humidity, visibility, wind_speed, precipitation, amenity,
|
| 11 |
+
bump, crossing, give_way, junction, no_exit, railway, station,
|
| 12 |
+
stop, traffic_signal, quarter):
|
| 13 |
+
encoded_quarter = qod_encoder.transform(pd.DataFrame([[quarter]], columns=qod_encoder.feature_names_in_))[0][0]
|
| 14 |
+
|
| 15 |
+
# Ensure checkbox values default to False if None
|
| 16 |
+
checkbox_values = [amenity, bump, crossing, give_way, junction, no_exit,
|
| 17 |
+
railway, station, stop, traffic_signal]
|
| 18 |
+
|
| 19 |
+
checkbox_values = [bool(value) if value is not None else False for value in checkbox_values]
|
| 20 |
+
|
| 21 |
+
print("Inputs Received:")
|
| 22 |
+
print(
|
| 23 |
+
f"quarter: {quarter} - {encoded_quarter}, pressure: {pressure}, temperature: {temperature}, "
|
| 24 |
+
f"humidity: {humidity}, visibility: {visibility}, wind_speed: {wind_speed}, "
|
| 25 |
+
f"precipitation: {precipitation}, "
|
| 26 |
+
f"amenity: {amenity}, bump: {bump}, crossing: {crossing}, give_way: {give_way}, "
|
| 27 |
+
f"junction: {junction}, no_exit: {no_exit}, railway: {railway}, "
|
| 28 |
+
f"station: {station}, stop: {stop}, traffic_signal: {traffic_signal}")
|
| 29 |
+
|
| 30 |
+
# Convert features to the required format
|
| 31 |
+
input_data = np.array([pressure, temperature, humidity, visibility,
|
| 32 |
+
wind_speed, precipitation, amenity, bump, crossing,
|
| 33 |
+
give_way, junction, no_exit, railway, station, stop, traffic_signal,
|
| 34 |
+
encoded_quarter]).reshape(1, -1)
|
| 35 |
+
prediction = model.predict(input_data)
|
| 36 |
+
return prediction[0]
|
| 37 |
+
|
| 38 |
+
# Create Gradio interface
|
| 39 |
+
iface = gr.Interface(
|
| 40 |
+
fn=predict,
|
| 41 |
+
inputs=[
|
| 42 |
+
|
| 43 |
+
gr.Number(label="Pressure(in)", minimum=27.31, maximum=30.61, value=27.31),
|
| 44 |
+
gr.Number(label="Temperature(in)", minimum=15.8, maximum=117, value=15.8),
|
| 45 |
+
gr.Number(label="Humidity(%)", minimum=2, maximum=100, value=100),
|
| 46 |
+
gr.Number(label="Visibility(mi)", minimum=0, maximum=80, value=0),
|
| 47 |
+
gr.Number(label="Wind Speed(mph)", minimum=0, maximum=73.6, value=0),
|
| 48 |
+
gr.Number(label="Precipitation", minimum=0, maximum=1, value=0),
|
| 49 |
+
|
| 50 |
+
gr.Checkbox(label="Amenity"),
|
| 51 |
+
gr.Checkbox(label="Bump"),
|
| 52 |
+
gr.Checkbox(label="Crossing"),
|
| 53 |
+
gr.Checkbox(label="Give Way"),
|
| 54 |
+
gr.Checkbox(label="Junction"),
|
| 55 |
+
gr.Checkbox(label="No Exit"),
|
| 56 |
+
gr.Checkbox(label="Railway"),
|
| 57 |
+
gr.Checkbox(label="Station"),
|
| 58 |
+
gr.Checkbox(label="Stop"),
|
| 59 |
+
gr.Checkbox(label="Traffic_Signal"),
|
| 60 |
+
gr.Dropdown(choices=['Q1', 'Q2', 'Q3', 'Q4'], label="Quarter of Day"),
|
| 61 |
+
|
| 62 |
+
],
|
| 63 |
+
outputs=gr.Textbox(label="Prediction")
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# Launch the interface
|
| 67 |
+
iface.launch()
|
joblib/qod_encoder_CA.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:26ab27c167c2f498e33b9c3056d473dbf2c70d969da111902e4b6a6328a17c5f
|
| 3 |
+
size 1066
|
joblib/rf_classifier_CA.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:84a0e314f9812de5039228d1795264c6db93bb98c048a9c28ff1340103b85e04
|
| 3 |
+
size 229375065
|