hacker4572's picture
Update app.py
56a3700 verified
Raw
History Blame Contribute Delete
1.25 kB
import pandas as pd
import gradio as gr
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score
from xgboost import XGBRegressor
#step 2 LOAD THE DATASET
data=pd.read_csv('uber_price_predictor.csv')
#step 3 SEPERATING DIPENDENT NAD IN-DEPENDENT ATTRIBUTES
x=data.drop('Price',axis=1)
y=data['Price']
#step 4 SPLITING THE DATASET
xtrain,xtest,ytrain,ytest=train_test_split(x,y,test_size=0.2,random_state=42)
# Step 5: Train the XGBoost model
model = XGBRegressor()
model.fit(xtrain, ytrain)
#Gradio
interface=gr.Interface(
fn=lambda Num_Cars_Available,Rain,Distance_km,Time_of_Day,Traffic_Level:f"Predict Uber Price: {model.predict([[Num_Cars_Available,Rain,Distance_km,Time_of_Day,Traffic_Level]])[0]:,.2f}",
inputs=[
gr.Number(label='enter Num_Cars_Available',value=3),
gr.Number(label="enter Rain amount",value=2),
gr.Number(label="enter Distence (km)",value=12),
gr.Number(label="enter Time_of_Day",value=3),
gr.Number(label="enter Traffic_Level", value=2),
],
outputs=gr.Textbox(label="Prediction"),
title="Uber Price Prediction",
description="Enter uber details to predict price using XGBoost."
)
if __name__ == "__main__":
interface.launch()