import gradio as gr import joblib import pandas as pd model = joblib.load("RandomForest.pkl") def predict_fare(airline, source, dep_time, stops, arr_time, dest, travel_class, duration, days_left): input_dict = { 'airline': [airline], 'source_city': [source], 'departure_time': [dep_time], 'arrival_time': [arr_time], 'destination_city': [dest], 'class': [0 if travel_class == "Economy" else 1], 'stops': [0 if stops == "zero" else 1 if stops == "one" else 2], 'duration': [duration], 'days_left': [days_left] } input_df = pd.DataFrame(input_dict) prediction = model.predict(input_df)[0] return f"₹ {round(prediction, 2)}" app = gr.Interface( fn=predict_fare, inputs=[ gr.Dropdown(['AirAsia', 'IndiGo', 'Vistara', 'SpiceJet', 'GO_FIRST'], label="Airline"), gr.Dropdown(['Delhi', 'Mumbai', 'Kolkata', 'Bangalore', 'Chennai'], label="Source City"), gr.Dropdown(['Morning', 'Evening', 'Afternoon', 'Night', 'Early Morning', 'Late Night'], label="Departure Time"), gr.Dropdown(['zero', 'one', 'two_or_more'], label="Stops"), gr.Dropdown(['Morning', 'Evening', 'Afternoon', 'Night', 'Early Morning', 'Late Night'], label="Arrival Time"), gr.Dropdown(['Delhi', 'Mumbai', 'Kolkata', 'Bangalore', 'Chennai'], label="Destination City"), gr.Dropdown(['Economy', 'Business'], label="Class"), gr.Number(label="Duration (hours)"), gr.Number(label="Days Left") ], outputs="text", title="Flight Fare Prediction", description="Enter flight details to estimate the fare." ) app.launch()