File size: 4,735 Bytes
d42ebdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import gradio as gr
import pandas as pd
import pickle


# Define params names
PARAMS_NAME = [
            "ph",
            "Hardness",
            "Solids",
            "Chloramines",
            "Sulfate",
            "Conductivity",
            "Organic_carbon",
            "Trihalomethanes",
            "Turbidity"
]

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




def predict(*args):
    answer_dict = {}

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

    # Crear dataframe
    single_instance = pd.DataFrame.from_dict(answer_dict)

 
    
    
    prediction = model.predict(single_instance)

    # Como sabemos el model nos devuelve los tipos de fraude 1, 2 y 3 en el response. Podemos devolver un response estilo semáforo.
    
    # Cast numpy.int64 to just a int
    Potability = int(prediction[0])


    # Adaptación respuesta
    response = Potability
    if Potability == 1:
        response = "Just Water, drink it 🥤"
    if Potability == 0:
        response = "Drink and you will DIE! ☠️ "


    return response


with gr.Blocks() as demo:
    gr.Markdown(
        """
        #  🏞️ Water Quality 
        """
    )

    with gr.Row():
        with gr.Column():

            gr.Markdown(
                """
                ## 🌊 Insert your water data here please 💦
                """
            )
            
            ph = gr.Slider(
                label='Ph',
                minimum=0.2274990502021987,
                maximum=13.999999999999998,
                step=0.1,
                randomize=True
            )

            Hardness = gr.Slider(
                label='Hardness',
                minimum=73.4922336890611,
                maximum=317.33812405558257,
                step=0.1,
                randomize=True
            )

            Solids = gr.Slider(
                label='Solids',
                minimum=320.942611274359,
                maximum=56488.67241273919,
                step=0.1,
                randomize=True
            )

            Chloramines = gr.Slider(
                label='Chloramines',
                minimum=1.3908709048851806,
                maximum=13.127000000000002,
                step=0.1,
                randomize=True
            )

            Sulfate = gr.Slider(
                label='Sulfate',
                minimum=129.00000000000003,
                maximum=481.0306423059972,
                step=0.1,
                randomize=True
            )

            Conductivity = gr.Slider(
                label='Conductivity',
                minimum=201.6197367551575,
                maximum=753.3426195583046,
                step=0.1,
                randomize=True
            )

            Organic_carbon = gr.Slider(
                label='Organic_Carbon',
                minimum=2.1999999999999886,
                maximum=27.00670661116601,
                step=0.1,
                randomize=True
            )

            Trihalomethanes = gr.Slider(
                label='Trihalomethanes',
                minimum=8.577012932983806,
                maximum=124.0,
                step=0.1,
                randomize=True
            )

            Turbidity = gr.Slider(
                label='Turbidity',
                minimum=1.45,
                maximum=6.494748555990993,
                step=0.1,
                randomize=True
            )


        with gr.Column():

            gr.Markdown(
                """
                ## Let's see if you can drink it 💧
                """
            )

            label = gr.Label(label="Kind of Water")
            predict_btn = gr.Button(value="Test")
            predict_btn.click(
                predict,
                inputs=[
                    ph,
                    Hardness,
                    Solids,
                    Chloramines,
                    Sulfate,
                    Conductivity,
                    Organic_carbon,
                    Trihalomethanes,
                    Turbidity,
                ],
                outputs=[label],
                api_name="prediccion"
            )
    gr.Markdown(
        """
        <p style='text-align: center'>
            <a href='https://www.escueladedatosvivos.ai/cursos/bootcamp-de-data-science' 
                target='_blank'>Proyecto demo creado en el bootcamp de EDVAI 🤗
            </a>
        </p>
        <p style='text-align: center'>
            <a href='https://www.kaggle.com/datasets/adityakadiwal/water-potability' 
                target='_blank'>Data From Water Quality in Kaggle
            </a>
        </p>
        """
    )

demo.launch()