Download app.py from sancho10/ASHISH: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/spaces/sancho10/ASHISH/resolve/main/app.py
- Command line
-
hf download hf://spaces/sancho10/ASHISH/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sancho10/ASHISH/resolve/main/app.py
1.47 kB
| import gradio as gr | |
| import pandas as pd | |
| import joblib | |
| # Load model and feature names | |
| model = joblib.load("crash_prediction_model.pkl") | |
| feature_columns = joblib.load("feature_columns.pkl") # Must match training order | |
| # Prediction function | |
| def predict_crash( | |
| frame_width, frame_height, | |
| total_vehicle_count, car_count, truck_count, | |
| bus_count, motorbike_count, vehicle_density, | |
| timestamp_sec | |
| ): | |
| # Create DataFrame with correct column names | |
| input_data = pd.DataFrame([[ | |
| frame_width, frame_height, | |
| total_vehicle_count, car_count, truck_count, | |
| bus_count, motorbike_count, vehicle_density, | |
| timestamp_sec | |
| ]], columns=feature_columns) | |
| # Predict | |
| prediction = model.predict(input_data)[0] | |
| label = "🚨 Crash Likely" if prediction == 1 else "✅ No Crash" | |
| return label | |
| # Gradio interface | |
| iface = gr.Interface( | |
| fn=predict_crash, | |
| title="Traffic Crash Prediction", | |
| description="Enter traffic features to predict if a crash is likely.", | |
| inputs=[ | |
| gr.Number(label="Frame Width"), | |
| gr.Number(label="Frame Height"), | |
| gr.Number(label="Total Vehicle Count"), | |
| gr.Number(label="Car Count"), | |
| gr.Number(label="Truck Count"), | |
| gr.Number(label="Bus Count"), | |
| gr.Number(label="Motorbike Count"), | |
| gr.Number(label="Vehicle Density"), | |
| gr.Number(label="Timestamp (in seconds)") | |
| ], | |
| outputs="text" | |
| ) | |
| # Launch app | |
| iface.launch() | |