Update PUE
Browse files
PUE
CHANGED
|
@@ -1,12 +1,37 @@
|
|
| 1 |
-
import joblib
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
# Load model once
|
| 6 |
artifact = joblib.load("pue_artifact.joblib")
|
| 7 |
|
| 8 |
-
def predict_pue(
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
X = X.reindex(columns=artifact["features"], fill_value=0)
|
| 11 |
|
| 12 |
ride = artifact["ride_encoder"].inverse_transform(
|
|
@@ -25,36 +50,9 @@ def predict_pue(input_dict):
|
|
| 25 |
"Preferred Route": route
|
| 26 |
}
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
distance_km, duration_min, base_fare,
|
| 32 |
-
avg_distance, avg_duration, avg_fare,
|
| 33 |
-
discount_usage_rate, total_rides
|
| 34 |
-
):
|
| 35 |
-
|
| 36 |
-
input_data = {
|
| 37 |
-
"zone_id": int(zone_id),
|
| 38 |
-
"hour": int(hour),
|
| 39 |
-
"day_of_week": int(day_of_week),
|
| 40 |
-
"is_weekend": int(is_weekend),
|
| 41 |
-
"weather_factor": weather_factor,
|
| 42 |
-
"event_factor": event_factor,
|
| 43 |
-
"traffic_index": traffic_index,
|
| 44 |
-
"distance_km": distance_km,
|
| 45 |
-
"duration_min": duration_min,
|
| 46 |
-
"base_fare": base_fare,
|
| 47 |
-
"avg_distance": avg_distance,
|
| 48 |
-
"avg_duration": avg_duration,
|
| 49 |
-
"avg_fare": avg_fare,
|
| 50 |
-
"discount_usage_rate": discount_usage_rate,
|
| 51 |
-
"total_rides": int(total_rides)
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
return predict_pue(input_data)
|
| 55 |
-
|
| 56 |
-
demo = gr.Interface(
|
| 57 |
-
fn=ui_predict,
|
| 58 |
inputs=[
|
| 59 |
gr.Number(label="Zone ID"),
|
| 60 |
gr.Slider(0,23,step=1,label="Hour"),
|
|
@@ -73,8 +71,8 @@ demo = gr.Interface(
|
|
| 73 |
gr.Number(label="Total Rides")
|
| 74 |
],
|
| 75 |
outputs="json",
|
| 76 |
-
title="Personalized User Experience –
|
| 77 |
-
description="Real-time personalization
|
| 78 |
)
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
+
import joblib
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# Load model artifact once
|
| 6 |
artifact = joblib.load("pue_artifact.joblib")
|
| 7 |
|
| 8 |
+
def predict_pue(
|
| 9 |
+
zone_id, hour, day_of_week, is_weekend,
|
| 10 |
+
weather_factor, event_factor, traffic_index,
|
| 11 |
+
distance_km, duration_min, base_fare,
|
| 12 |
+
avg_distance, avg_duration, avg_fare,
|
| 13 |
+
discount_usage_rate, total_rides
|
| 14 |
+
):
|
| 15 |
+
|
| 16 |
+
input_data = {
|
| 17 |
+
"zone_id": int(zone_id),
|
| 18 |
+
"hour": int(hour),
|
| 19 |
+
"day_of_week": int(day_of_week),
|
| 20 |
+
"is_weekend": int(is_weekend),
|
| 21 |
+
"weather_factor": float(weather_factor),
|
| 22 |
+
"event_factor": float(event_factor),
|
| 23 |
+
"traffic_index": float(traffic_index),
|
| 24 |
+
"distance_km": float(distance_km),
|
| 25 |
+
"duration_min": float(duration_min),
|
| 26 |
+
"base_fare": float(base_fare),
|
| 27 |
+
"avg_distance": float(avg_distance),
|
| 28 |
+
"avg_duration": float(avg_duration),
|
| 29 |
+
"avg_fare": float(avg_fare),
|
| 30 |
+
"discount_usage_rate": float(discount_usage_rate),
|
| 31 |
+
"total_rides": int(total_rides)
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
X = pd.DataFrame([input_data])
|
| 35 |
X = X.reindex(columns=artifact["features"], fill_value=0)
|
| 36 |
|
| 37 |
ride = artifact["ride_encoder"].inverse_transform(
|
|
|
|
| 50 |
"Preferred Route": route
|
| 51 |
}
|
| 52 |
|
| 53 |
+
# Gradio UI
|
| 54 |
+
app = gr.Interface(
|
| 55 |
+
fn=predict_pue,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
inputs=[
|
| 57 |
gr.Number(label="Zone ID"),
|
| 58 |
gr.Slider(0,23,step=1,label="Hour"),
|
|
|
|
| 71 |
gr.Number(label="Total Rides")
|
| 72 |
],
|
| 73 |
outputs="json",
|
| 74 |
+
title="Personalized User Experience – Real-Time ML",
|
| 75 |
+
description="Real-time personalization for ride-hailing apps"
|
| 76 |
)
|
| 77 |
|
| 78 |
+
app.launch()
|