forked from pranshujoshi09/Cancer-Risk-Classification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprediction.py
78 lines (66 loc) · 2.3 KB
/
prediction.py
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
import streamlit as st
import pickle
import numpy as np
from pydantic import BaseModel, ValidationError
model = pickle.load(open("cancer_model.pkl", "rb"))
class CancerDetectionRequest(BaseModel):
Schiller: bool
Hinselmann: bool
Citology: bool
STDs: bool
hormonal_contraceptives_years: int
Smokes_years: int
iud: bool
age: int
hormonal_contraceptives: bool
iud_years: int
# Prediction function
def predict_cervical_cancer(data):
features = [
int(data['Schiller']),
int(data['Hinselmann']),
int(data['Citology']),
int(data['STDs']),
data['hormonal_contraceptives_years'],
data['Smokes_years'],
int(data['iud']),
data['age'],
int(data['hormonal_contraceptives']),
data['iud_years']
]
result = model.predict([features])[0]
if result == 0:
return "Low risk of cervical cancer"
else:
return "High risk of cervical cancer"
# Streamlit UI
st.title("Cervical Cancer Risk Prediction")
Schiller = st.checkbox("Schiller Test Result")
Hinselmann = st.checkbox("Hinselmann Test Result")
Citology = st.checkbox("Citology Test Result")
STDs = st.checkbox("History of STDs")
hormonal_contraceptives_years = st.number_input("Years of Hormonal Contraceptives Use", min_value=0, max_value=50, value=0)
Smokes_years = st.number_input("Years of Smoking", min_value=0, max_value=50, value=0)
iud = st.checkbox("IUD Usage")
age = st.number_input("Age", min_value=0, max_value=120, value=30)
hormonal_contraceptives = st.checkbox("Currently Using Hormonal Contraceptives")
iud_years = st.number_input("Years of IUD Use", min_value=0, max_value=50, value=0)
if st.button("Predict"):
data = {
"Schiller": Schiller,
"Hinselmann": Hinselmann,
"Citology": Citology,
"STDs": STDs,
"hormonal_contraceptives_years": hormonal_contraceptives_years,
"Smokes_years": Smokes_years,
"iud": iud,
"age": age,
"hormonal_contraceptives": hormonal_contraceptives,
"iud_years": iud_years
}
try:
request = CancerDetectionRequest(**data)
prediction = predict_cervical_cancer(data)
st.success(f"Prediction: {prediction}")
except ValidationError as e:
st.error(f"Validation Error: {e}")