File size: 1,662 Bytes
15b5435
 
 
 
010c3e1
15b5435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9dbf05b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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()