Spaces:
Sleeping

Murriel commited on
Commit
a984d1d
·
verified ·
1 Parent(s): e7df257

Delete predict.py

Browse files
Files changed (1) hide show
  1. predict.py +0 -66
predict.py DELETED
@@ -1,66 +0,0 @@
1
- import gradio as gr
2
- import pandas as pd
3
- from PIL import Image
4
- from sklearn.model_selection import train_test_split
5
- from sklearn.ensemble import RandomForestClassifier
6
-
7
- df=pd.read_csv('Dataset/water_potability.csv')
8
- for i in ['ph','Trihalomethanes','Sulfate']:
9
- missing1 = df.query('Potability == 0')[i][df[i].isna()].index
10
- df.loc[missing1,i] = df.query('Potability == 0')[i][df[i].notna()].mean()
11
- missing2 = df.query('Potability == 1')[i][df[i].isna()].index
12
- df.loc[missing2,i] = df.query('Potability == 1')[i][df[i].notna()].mean()
13
-
14
- dataInp=df.drop('Potability',axis=1)
15
- dataOp=df['Potability']
16
- X_train,X_test,y_train,y_test=train_test_split(dataInp,dataOp,test_size=0.25,random_state=42)
17
- model= RandomForestClassifier()
18
- model.fit(X_train,y_train)
19
-
20
-
21
- inputs = [
22
- gr.Number(label='ph', default=6.5),
23
- gr.Number(label='Hardness', default=1),
24
- gr.Number(label='Solids', default=500),
25
- gr.Number(label='Chloramines', default=4),
26
- gr.Number(label='Sulfate', default=250),
27
- gr.Number(label='Conductivity', default=800),
28
- gr.Number(label='Organic_Carbon', default=2),
29
- gr.Number(label='Trihalomethanes', default=80),
30
- gr.Number(label='Turbidity', default=5)
31
- ]
32
-
33
- outputs = [
34
- gr.Label(label="Potability"),
35
- gr.Image(type='pil',label="Image")
36
- ]
37
-
38
-
39
- def predict_water_quality(ph, Hardness, Solids, Chloramines, Sulfate, Conductivity, Organic_Carbon, Trihalomethanes, Turbidity):
40
-
41
- try:
42
- data=pd.DataFrame({'ph':[ph],'Hardness':[Hardness],'Solids':[Solids],
43
- 'Chloramines':[Chloramines],'Sulfate':[Sulfate],'Conductivity':[Conductivity],
44
- 'Organic_carbon':[Organic_Carbon],'Trihalomethanes':[Trihalomethanes],'Turbidity':[Turbidity]})
45
- X_new=data[['ph','Hardness','Solids','Chloramines','Sulfate','Conductivity','Organic_carbon','Trihalomethanes','Turbidity']]
46
- prediction = model.predict(X_new)
47
- potable_water = Image.open("images/Portable.png")
48
- non_potable_water = Image.open("images/Nonportable.jpg")
49
-
50
- if prediction== 1:
51
- image = potable_water
52
- else:
53
- image = non_potable_water
54
- if prediction==0:
55
- print('Non Potable water')
56
- return 'Non Potable water',image
57
- else:
58
- print('Potable water')
59
- return 'Potable water',image
60
-
61
- except Exception as e:
62
- return (e)
63
-
64
- app = gr.Interface(fn=predict_water_quality,inputs=inputs, outputs=outputs,description='Water quality is a crucial aspect of public health, and the potability of water samples is a significant concern for people worldwide. Predicting whether a water sample is potable or not is a critical task that can be accomplished through the use of machine learning techniques. \n One approach to predicting water potability is to use a Random Forest Classifier model. The model can take in various features of the water sample, such as pH, hardness, solid content, turbidity, sulfate content, trihalomethanes, conductivity, and organic carbon content, as input. Each of these features is a potential contributor to water potability.', css="footer {visibility: hidden}", title='Water Potability Prediction')
65
- app.launch()
66
-