File size: 3,037 Bytes
425853e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f72dbc2
425853e
99e9aa5
836cbb0
99e9aa5
836cbb0
2c99c21
425853e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c18befd
425853e
 
 
 
 
 
 
c18befd
425853e
c18befd
425853e
c18befd
425853e
c18befd
425853e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
efb2e16
425853e
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import gradio as gr
import pickle
import pandas as pd


PARAMS_NAME = [
    "Age",
    "Class",
    "Wifi",
    "Booking",
    "Seat",
    "Checkin"
]


with open("model/rf.pkl", "rb") as f:
    model = pickle.load(f)

COLUMNS_PATH = "model/categories_ohe.pickle"
with open(COLUMNS_PATH, 'rb') as handle:
    ohe_tr = pickle.load(handle)


def predict(*args):
    answer_dict = {}

    for i in range(len(PARAMS_NAME)):
        answer_dict[PARAMS_NAME[i]] = [args[i]]

    single_instance = pd.DataFrame.from_dict(answer_dict)

    # Reformat columns
    single_instance_ohe = pd.get_dummies(single_instance).reindex(columns = ohe_tr).fillna(0)
    
    prediction = model.predict(single_instance_ohe)

    response = int(prediction[0])

    if response == 0:
        response = "This flight was a really hell!!"
    if response == 1:
        response = "I have touch the sky with my hand, what a lovely flight!"

    return response

with gr.Blocks() as demo:
        gr.Markdown(
        '''
        # Flight satisfaction 🛩
        '''
        )

        with gr.Row():
            with gr.Column():
                
                gr.Markdown(
                    '''
                        ## Input 🛫

                    '''
                )

                Age = gr.Slider(label="Age", minimum=6, maximum=120, step=1, randomize=True)

                Class = gr.Radio(
                    label="Class",
                    choices=["Business", "Eco", "Eco Plus"],
                    value="Eco Plus"
                )

                Wifi = gr.Slider(label="Wifi", minimum=1, maximum=5, step=1, randomize=True)

                Booking = gr.Slider(label="Booking", minimum=1, maximum=5, step=1, randomize=True)

                Seat = gr.Slider(label="Seat", minimum=1, maximum=5, step=1, randomize=True)

                Checkin = gr.Slider(label="Checkin", minimum=1, maximum=5, step=1, randomize=True)

            with gr.Column():

                gr.Markdown(
                    '''
                        ## Prediction 🛬

                    '''
                )

                label = gr.Label(label="Satisfaction")
                predict_btn = gr.Button(value="Shoot")
                predict_btn.click(
                    predict,
                    inputs=[
                        Age,
                        Class,
                        Wifi,
                        Booking,
                        Seat,
                        Checkin,
                    ],
                    outputs=[label],
                    api_name="Flight satisfaction"
                )
        gr.Markdown(
            '''

            <p style='text-align:center'>
                <a href='https://www.escueladedatosvivos.ai/cursos/bootcamp-de-data-science'
                    target='_blank'>Estudia con Carlos Bustillo en Escuela de Datos Vivos haciendo click aqui y hace muchas de estas APIS 😎 !
                </a>
            </p>
            '''
        )

demo.launch()