Spaces:
Sleeping
Sleeping
| 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() | |