Spaces:
Sleeping
Sleeping
Commit ·
d42ebdf
1
Parent(s): 9fbca95
Labels
Browse files155 Change TIpo de Fraude for KInd of Water
156 Change Evalur for Test
app.py
CHANGED
|
@@ -1,188 +1,188 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import pickle
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
# Define params names
|
| 7 |
-
PARAMS_NAME = [
|
| 8 |
-
"ph",
|
| 9 |
-
"Hardness",
|
| 10 |
-
"Solids",
|
| 11 |
-
"Chloramines",
|
| 12 |
-
"Sulfate",
|
| 13 |
-
"Conductivity",
|
| 14 |
-
"Organic_carbon",
|
| 15 |
-
"Trihalomethanes",
|
| 16 |
-
"Turbidity"
|
| 17 |
-
]
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
# Load model
|
| 21 |
-
with open("model/model1.pkl", "rb") as f:
|
| 22 |
-
model = pickle.load(f)
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
def predict(*args):
|
| 28 |
-
answer_dict = {}
|
| 29 |
-
|
| 30 |
-
for i in range(len(PARAMS_NAME)):
|
| 31 |
-
answer_dict[PARAMS_NAME[i]] = [args[i]]
|
| 32 |
-
|
| 33 |
-
# Crear dataframe
|
| 34 |
-
single_instance = pd.DataFrame.from_dict(answer_dict)
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
prediction = model.predict(single_instance)
|
| 40 |
-
|
| 41 |
-
# Como sabemos el model nos devuelve los tipos de fraude 1, 2 y 3 en el response. Podemos devolver un response estilo semáforo.
|
| 42 |
-
|
| 43 |
-
# Cast numpy.int64 to just a int
|
| 44 |
-
Potability = int(prediction[0])
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
# Adaptación respuesta
|
| 48 |
-
response = Potability
|
| 49 |
-
if Potability == 1:
|
| 50 |
-
response = "Just Water, drink it 🥤"
|
| 51 |
-
if Potability == 0:
|
| 52 |
-
response = "Drink and you will DIE! ☠️ "
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
return response
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
with gr.Blocks() as demo:
|
| 59 |
-
gr.Markdown(
|
| 60 |
-
"""
|
| 61 |
-
# 🏞️ Water Quality
|
| 62 |
-
"""
|
| 63 |
-
)
|
| 64 |
-
|
| 65 |
-
with gr.Row():
|
| 66 |
-
with gr.Column():
|
| 67 |
-
|
| 68 |
-
gr.Markdown(
|
| 69 |
-
"""
|
| 70 |
-
## 🌊 Insert your water data here please 💦
|
| 71 |
-
"""
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
ph = gr.Slider(
|
| 75 |
-
label='Ph',
|
| 76 |
-
minimum=0.2274990502021987,
|
| 77 |
-
maximum=13.999999999999998,
|
| 78 |
-
step=0.1,
|
| 79 |
-
randomize=True
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
Hardness = gr.Slider(
|
| 83 |
-
label='Hardness',
|
| 84 |
-
minimum=73.4922336890611,
|
| 85 |
-
maximum=317.33812405558257,
|
| 86 |
-
step=0.1,
|
| 87 |
-
randomize=True
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
-
Solids = gr.Slider(
|
| 91 |
-
label='Solids',
|
| 92 |
-
minimum=320.942611274359,
|
| 93 |
-
maximum=56488.67241273919,
|
| 94 |
-
step=0.1,
|
| 95 |
-
randomize=True
|
| 96 |
-
)
|
| 97 |
-
|
| 98 |
-
Chloramines = gr.Slider(
|
| 99 |
-
label='Chloramines',
|
| 100 |
-
minimum=1.3908709048851806,
|
| 101 |
-
maximum=13.127000000000002,
|
| 102 |
-
step=0.1,
|
| 103 |
-
randomize=True
|
| 104 |
-
)
|
| 105 |
-
|
| 106 |
-
Sulfate = gr.Slider(
|
| 107 |
-
label='Sulfate',
|
| 108 |
-
minimum=129.00000000000003,
|
| 109 |
-
maximum=481.0306423059972,
|
| 110 |
-
step=0.1,
|
| 111 |
-
randomize=True
|
| 112 |
-
)
|
| 113 |
-
|
| 114 |
-
Conductivity = gr.Slider(
|
| 115 |
-
label='Conductivity',
|
| 116 |
-
minimum=201.6197367551575,
|
| 117 |
-
maximum=753.3426195583046,
|
| 118 |
-
step=0.1,
|
| 119 |
-
randomize=True
|
| 120 |
-
)
|
| 121 |
-
|
| 122 |
-
Organic_carbon = gr.Slider(
|
| 123 |
-
label='Organic_Carbon',
|
| 124 |
-
minimum=2.1999999999999886,
|
| 125 |
-
maximum=27.00670661116601,
|
| 126 |
-
step=0.1,
|
| 127 |
-
randomize=True
|
| 128 |
-
)
|
| 129 |
-
|
| 130 |
-
Trihalomethanes = gr.Slider(
|
| 131 |
-
label='Trihalomethanes',
|
| 132 |
-
minimum=8.577012932983806,
|
| 133 |
-
maximum=124.0,
|
| 134 |
-
step=0.1,
|
| 135 |
-
randomize=True
|
| 136 |
-
)
|
| 137 |
-
|
| 138 |
-
Turbidity = gr.Slider(
|
| 139 |
-
label='Turbidity',
|
| 140 |
-
minimum=1.45,
|
| 141 |
-
maximum=6.494748555990993,
|
| 142 |
-
step=0.1,
|
| 143 |
-
randomize=True
|
| 144 |
-
)
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
with gr.Column():
|
| 148 |
-
|
| 149 |
-
gr.Markdown(
|
| 150 |
-
"""
|
| 151 |
-
## Let's see if you can drink it 💧
|
| 152 |
-
"""
|
| 153 |
-
)
|
| 154 |
-
|
| 155 |
-
label = gr.Label(label="
|
| 156 |
-
predict_btn = gr.Button(value="
|
| 157 |
-
predict_btn.click(
|
| 158 |
-
predict,
|
| 159 |
-
inputs=[
|
| 160 |
-
ph,
|
| 161 |
-
Hardness,
|
| 162 |
-
Solids,
|
| 163 |
-
Chloramines,
|
| 164 |
-
Sulfate,
|
| 165 |
-
Conductivity,
|
| 166 |
-
Organic_carbon,
|
| 167 |
-
Trihalomethanes,
|
| 168 |
-
Turbidity,
|
| 169 |
-
],
|
| 170 |
-
outputs=[label],
|
| 171 |
-
api_name="prediccion"
|
| 172 |
-
)
|
| 173 |
-
gr.Markdown(
|
| 174 |
-
"""
|
| 175 |
-
<p style='text-align: center'>
|
| 176 |
-
<a href='https://www.escueladedatosvivos.ai/cursos/bootcamp-de-data-science'
|
| 177 |
-
target='_blank'>Proyecto demo creado en el bootcamp de EDVAI 🤗
|
| 178 |
-
</a>
|
| 179 |
-
</p>
|
| 180 |
-
<p style='text-align: center'>
|
| 181 |
-
<a href='https://www.kaggle.com/datasets/adityakadiwal/water-potability'
|
| 182 |
-
target='_blank'>Data From Water Quality in Kaggle
|
| 183 |
-
</a>
|
| 184 |
-
</p>
|
| 185 |
-
"""
|
| 186 |
-
)
|
| 187 |
-
|
| 188 |
-
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import pickle
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# Define params names
|
| 7 |
+
PARAMS_NAME = [
|
| 8 |
+
"ph",
|
| 9 |
+
"Hardness",
|
| 10 |
+
"Solids",
|
| 11 |
+
"Chloramines",
|
| 12 |
+
"Sulfate",
|
| 13 |
+
"Conductivity",
|
| 14 |
+
"Organic_carbon",
|
| 15 |
+
"Trihalomethanes",
|
| 16 |
+
"Turbidity"
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# Load model
|
| 21 |
+
with open("model/model1.pkl", "rb") as f:
|
| 22 |
+
model = pickle.load(f)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def predict(*args):
|
| 28 |
+
answer_dict = {}
|
| 29 |
+
|
| 30 |
+
for i in range(len(PARAMS_NAME)):
|
| 31 |
+
answer_dict[PARAMS_NAME[i]] = [args[i]]
|
| 32 |
+
|
| 33 |
+
# Crear dataframe
|
| 34 |
+
single_instance = pd.DataFrame.from_dict(answer_dict)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
prediction = model.predict(single_instance)
|
| 40 |
+
|
| 41 |
+
# Como sabemos el model nos devuelve los tipos de fraude 1, 2 y 3 en el response. Podemos devolver un response estilo semáforo.
|
| 42 |
+
|
| 43 |
+
# Cast numpy.int64 to just a int
|
| 44 |
+
Potability = int(prediction[0])
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
# Adaptación respuesta
|
| 48 |
+
response = Potability
|
| 49 |
+
if Potability == 1:
|
| 50 |
+
response = "Just Water, drink it 🥤"
|
| 51 |
+
if Potability == 0:
|
| 52 |
+
response = "Drink and you will DIE! ☠️ "
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
return response
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
with gr.Blocks() as demo:
|
| 59 |
+
gr.Markdown(
|
| 60 |
+
"""
|
| 61 |
+
# 🏞️ Water Quality
|
| 62 |
+
"""
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
with gr.Row():
|
| 66 |
+
with gr.Column():
|
| 67 |
+
|
| 68 |
+
gr.Markdown(
|
| 69 |
+
"""
|
| 70 |
+
## 🌊 Insert your water data here please 💦
|
| 71 |
+
"""
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
ph = gr.Slider(
|
| 75 |
+
label='Ph',
|
| 76 |
+
minimum=0.2274990502021987,
|
| 77 |
+
maximum=13.999999999999998,
|
| 78 |
+
step=0.1,
|
| 79 |
+
randomize=True
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
Hardness = gr.Slider(
|
| 83 |
+
label='Hardness',
|
| 84 |
+
minimum=73.4922336890611,
|
| 85 |
+
maximum=317.33812405558257,
|
| 86 |
+
step=0.1,
|
| 87 |
+
randomize=True
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
Solids = gr.Slider(
|
| 91 |
+
label='Solids',
|
| 92 |
+
minimum=320.942611274359,
|
| 93 |
+
maximum=56488.67241273919,
|
| 94 |
+
step=0.1,
|
| 95 |
+
randomize=True
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
Chloramines = gr.Slider(
|
| 99 |
+
label='Chloramines',
|
| 100 |
+
minimum=1.3908709048851806,
|
| 101 |
+
maximum=13.127000000000002,
|
| 102 |
+
step=0.1,
|
| 103 |
+
randomize=True
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
Sulfate = gr.Slider(
|
| 107 |
+
label='Sulfate',
|
| 108 |
+
minimum=129.00000000000003,
|
| 109 |
+
maximum=481.0306423059972,
|
| 110 |
+
step=0.1,
|
| 111 |
+
randomize=True
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
Conductivity = gr.Slider(
|
| 115 |
+
label='Conductivity',
|
| 116 |
+
minimum=201.6197367551575,
|
| 117 |
+
maximum=753.3426195583046,
|
| 118 |
+
step=0.1,
|
| 119 |
+
randomize=True
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
Organic_carbon = gr.Slider(
|
| 123 |
+
label='Organic_Carbon',
|
| 124 |
+
minimum=2.1999999999999886,
|
| 125 |
+
maximum=27.00670661116601,
|
| 126 |
+
step=0.1,
|
| 127 |
+
randomize=True
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
Trihalomethanes = gr.Slider(
|
| 131 |
+
label='Trihalomethanes',
|
| 132 |
+
minimum=8.577012932983806,
|
| 133 |
+
maximum=124.0,
|
| 134 |
+
step=0.1,
|
| 135 |
+
randomize=True
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
Turbidity = gr.Slider(
|
| 139 |
+
label='Turbidity',
|
| 140 |
+
minimum=1.45,
|
| 141 |
+
maximum=6.494748555990993,
|
| 142 |
+
step=0.1,
|
| 143 |
+
randomize=True
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
with gr.Column():
|
| 148 |
+
|
| 149 |
+
gr.Markdown(
|
| 150 |
+
"""
|
| 151 |
+
## Let's see if you can drink it 💧
|
| 152 |
+
"""
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
label = gr.Label(label="Kind of Water")
|
| 156 |
+
predict_btn = gr.Button(value="Test")
|
| 157 |
+
predict_btn.click(
|
| 158 |
+
predict,
|
| 159 |
+
inputs=[
|
| 160 |
+
ph,
|
| 161 |
+
Hardness,
|
| 162 |
+
Solids,
|
| 163 |
+
Chloramines,
|
| 164 |
+
Sulfate,
|
| 165 |
+
Conductivity,
|
| 166 |
+
Organic_carbon,
|
| 167 |
+
Trihalomethanes,
|
| 168 |
+
Turbidity,
|
| 169 |
+
],
|
| 170 |
+
outputs=[label],
|
| 171 |
+
api_name="prediccion"
|
| 172 |
+
)
|
| 173 |
+
gr.Markdown(
|
| 174 |
+
"""
|
| 175 |
+
<p style='text-align: center'>
|
| 176 |
+
<a href='https://www.escueladedatosvivos.ai/cursos/bootcamp-de-data-science'
|
| 177 |
+
target='_blank'>Proyecto demo creado en el bootcamp de EDVAI 🤗
|
| 178 |
+
</a>
|
| 179 |
+
</p>
|
| 180 |
+
<p style='text-align: center'>
|
| 181 |
+
<a href='https://www.kaggle.com/datasets/adityakadiwal/water-potability'
|
| 182 |
+
target='_blank'>Data From Water Quality in Kaggle
|
| 183 |
+
</a>
|
| 184 |
+
</p>
|
| 185 |
+
"""
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
demo.launch()
|