NicoGargano commited on
Commit
9fbca95
·
1 Parent(s): 4725b8f

Cargando Model

Browse files
Files changed (4) hide show
  1. app.py +188 -0
  2. model/.gitattributes +1 -0
  3. model/model1.pkl +3 -0
  4. requirements.txt +183 -0
app.py ADDED
@@ -0,0 +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="Tipo de Fraude")
156
+ predict_btn = gr.Button(value="Evaluar")
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()
model/.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ *.pkl filter=lfs diff=lfs merge=lfs -text
model/model1.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ebd89908c4a005e70df85161aeca87fadf7ef882e5bd317af9f679e713525b4e
3
+ size 39354808
requirements.txt ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ alembic==1.12.0
3
+ altair==5.1.1
4
+ annotated-types==0.5.0
5
+ anyio==3.7.1
6
+ argon2-cffi==23.1.0
7
+ argon2-cffi-bindings==21.2.0
8
+ arrow==1.2.3
9
+ asttokens==2.4.0
10
+ async-lru==2.0.4
11
+ attrs==23.1.0
12
+ Babel==2.12.1
13
+ backcall==0.2.0
14
+ beautifulsoup4==4.12.2
15
+ bleach==6.0.0
16
+ blinker==1.6.2
17
+ certifi==2023.7.22
18
+ cffi==1.15.1
19
+ cfgv==3.4.0
20
+ charset-normalizer==3.2.0
21
+ click==8.1.7
22
+ cloudpickle==2.2.1
23
+ comm==0.1.4
24
+ contourpy==1.1.1
25
+ cycler==0.11.0
26
+ databricks-cli==0.17.8
27
+ dearpygui==1.10.0
28
+ debugpy==1.8.0
29
+ decorator==5.1.1
30
+ defusedxml==0.7.1
31
+ distlib==0.3.7
32
+ docker==6.1.3
33
+ entrypoints==0.4
34
+ exceptiongroup==1.1.3
35
+ executing==1.2.0
36
+ fastapi==0.103.1
37
+ fastjsonschema==2.18.0
38
+ ffmpy==0.3.1
39
+ filelock==3.12.4
40
+ flake8==6.1.0
41
+ Flask==2.3.3
42
+ fonttools==4.42.1
43
+ fqdn==1.5.1
44
+ fsspec==2023.9.2
45
+ funpymodeling==0.1.8
46
+ gfs==1.0.1
47
+ gitdb==4.0.10
48
+ GitPython==3.1.37
49
+ gradio==3.44.4
50
+ gradio_client==0.5.1
51
+ greenlet==2.0.2
52
+ gunicorn==21.2.0
53
+ h11==0.14.0
54
+ httpcore==0.18.0
55
+ httpx==0.25.0
56
+ huggingface-hub==0.17.2
57
+ identify==2.5.29
58
+ idna==3.4
59
+ importlib-metadata==6.8.0
60
+ importlib-resources==6.1.0
61
+ iniconfig==2.0.0
62
+ ipykernel==6.25.2
63
+ ipython==8.15.0
64
+ ipython-genutils==0.2.0
65
+ ipywidgets==8.1.1
66
+ isoduration==20.11.0
67
+ itsdangerous==2.1.2
68
+ jedi==0.19.0
69
+ Jinja2==3.1.2
70
+ joblib==1.3.2
71
+ json5==0.9.14
72
+ jsonpointer==2.4
73
+ jsonschema==4.19.1
74
+ jsonschema-specifications==2023.7.1
75
+ jupyter==1.0.0
76
+ jupyter-console==6.6.3
77
+ jupyter-events==0.7.0
78
+ jupyter-lsp==2.2.0
79
+ jupyter_client==8.3.1
80
+ jupyter_core==5.3.1
81
+ jupyter_server==2.7.3
82
+ jupyter_server_terminals==0.4.4
83
+ jupyterlab==4.0.6
84
+ jupyterlab-pygments==0.2.2
85
+ jupyterlab-widgets==3.0.9
86
+ jupyterlab_server==2.25.0
87
+ kiwisolver==1.4.5
88
+ Mako==1.2.4
89
+ Markdown==3.4.4
90
+ MarkupSafe==2.1.3
91
+ matplotlib==3.8.0
92
+ matplotlib-inline==0.1.6
93
+ mccabe==0.7.0
94
+ mistune==3.0.1
95
+ mlflow==2.7.1
96
+ nbclient==0.8.0
97
+ nbconvert==7.8.0
98
+ nbformat==5.9.2
99
+ nest-asyncio==1.5.8
100
+ nodeenv==1.8.0
101
+ notebook==7.0.4
102
+ notebook_shim==0.2.3
103
+ numpy==1.26.0
104
+ oauthlib==3.2.2
105
+ orjson==3.9.7
106
+ overrides==7.4.0
107
+ packaging==23.1
108
+ pandas==2.1.1
109
+ pandocfilters==1.5.0
110
+ parso==0.8.3
111
+ pexpect==4.8.0
112
+ pickleshare==0.7.5
113
+ Pillow==10.0.1
114
+ platformdirs==3.10.0
115
+ pluggy==1.3.0
116
+ pre-commit==3.4.0
117
+ prometheus-client==0.17.1
118
+ prompt-toolkit==3.0.39
119
+ protobuf==4.24.3
120
+ psutil==5.9.5
121
+ ptyprocess==0.7.0
122
+ pure-eval==0.2.2
123
+ pyarrow==13.0.0
124
+ pycodestyle==2.11.0
125
+ pycparser==2.21
126
+ pydantic==2.4.0
127
+ pydantic_core==2.10.0
128
+ pydub==0.25.1
129
+ pyflakes==3.1.0
130
+ Pygments==2.16.1
131
+ PyJWT==2.8.0
132
+ pyparsing==3.1.1
133
+ pytest==7.4.2
134
+ python-dateutil==2.8.2
135
+ python-json-logger==2.0.7
136
+ python-multipart==0.0.6
137
+ pytz==2023.3.post1
138
+ PyYAML==6.0.1
139
+ pyzmq==25.1.1
140
+ qtconsole==5.4.4
141
+ QtPy==2.4.0
142
+ querystring-parser==1.2.4
143
+ referencing==0.30.2
144
+ requests==2.31.0
145
+ rfc3339-validator==0.1.4
146
+ rfc3986-validator==0.1.1
147
+ rpds-py==0.10.3
148
+ scikit-learn==1.3.1
149
+ scipy==1.11.2
150
+ seaborn==0.12.2
151
+ semantic-version==2.10.0
152
+ Send2Trash==1.8.2
153
+ six==1.16.0
154
+ smmap==5.0.1
155
+ sniffio==1.3.0
156
+ soupsieve==2.5
157
+ SQLAlchemy==2.0.21
158
+ sqlparse==0.4.4
159
+ stack-data==0.6.2
160
+ starlette==0.27.0
161
+ tabulate==0.9.0
162
+ terminado==0.17.1
163
+ threadpoolctl==3.2.0
164
+ tinycss2==1.2.1
165
+ tomli==2.0.1
166
+ toolz==0.12.0
167
+ tornado==6.3.3
168
+ tqdm==4.66.1
169
+ traitlets==5.10.0
170
+ typing_extensions==4.8.0
171
+ tzdata==2023.3
172
+ uri-template==1.3.0
173
+ urllib3==1.26.16
174
+ uvicorn==0.23.2
175
+ virtualenv==20.24.5
176
+ wcwidth==0.2.6
177
+ webcolors==1.13
178
+ webencodings==0.5.1
179
+ websocket-client==1.6.3
180
+ websockets==11.0.3
181
+ Werkzeug==2.3.7
182
+ widgetsnbextension==4.0.9
183
+ zipp==3.17.0