Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- .gitignore +6 -0
- app.py +116 -0
- knn_model.joblib +3 -0
- requirements.txt +4 -0
- tfidf_vectorizer.joblib +3 -0
.gitignore
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.pyc
|
2 |
+
__pycache__/
|
3 |
+
.env
|
4 |
+
.streamlit/
|
5 |
+
venv/
|
6 |
+
.vscode/
|
app.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import joblib
|
3 |
+
import re
|
4 |
+
import string
|
5 |
+
|
6 |
+
# Load the trained model and TF-IDF vectorizer
|
7 |
+
knn_model = joblib.load('knn_model.joblib')
|
8 |
+
tfidf_vectorizer = joblib.load('tfidf_vectorizer.joblib')
|
9 |
+
|
10 |
+
# Preprocess the input text (same preprocessing as in the notebook)
|
11 |
+
def preprocess_text(text):
|
12 |
+
text = text.lower() # Convert to lowercase
|
13 |
+
text = re.sub(r'\d+', '', text) # Remove digits
|
14 |
+
text = text.translate(str.maketrans('', '', string.punctuation)) # Remove punctuation
|
15 |
+
return text
|
16 |
+
|
17 |
+
# Prediction function
|
18 |
+
def predict_disease(symptom):
|
19 |
+
preprocessed_symptom = preprocess_text(symptom)
|
20 |
+
tfidf_features = tfidf_vectorizer.transform([preprocessed_symptom]).toarray()
|
21 |
+
predicted_disease = knn_model.predict(tfidf_features)
|
22 |
+
return predicted_disease[0]
|
23 |
+
|
24 |
+
# Streamlit UI Design
|
25 |
+
st.set_page_config(page_title="Disease Prediction App", page_icon="🦠", layout="centered")
|
26 |
+
|
27 |
+
# Custom Styling
|
28 |
+
st.markdown("""
|
29 |
+
<style>
|
30 |
+
body {
|
31 |
+
background-color: #2E2E2E;
|
32 |
+
color: white;
|
33 |
+
font-family: 'Segoe UI', sans-serif;
|
34 |
+
}
|
35 |
+
.header {
|
36 |
+
font-size: 36px;
|
37 |
+
font-weight: bold;
|
38 |
+
color: #00BFFF;
|
39 |
+
text-align: center;
|
40 |
+
margin-top: 30px;
|
41 |
+
margin-bottom: 15px;
|
42 |
+
}
|
43 |
+
.description {
|
44 |
+
font-size: 16px;
|
45 |
+
color: #dcdcdc;
|
46 |
+
text-align: center;
|
47 |
+
margin-bottom: 20px;
|
48 |
+
}
|
49 |
+
.input-box {
|
50 |
+
background-color: #3E3E3E;
|
51 |
+
border-radius: 8px;
|
52 |
+
padding: 15px;
|
53 |
+
font-size: 16px;
|
54 |
+
font-family: 'Segoe UI', sans-serif;
|
55 |
+
border: none;
|
56 |
+
color: white;
|
57 |
+
}
|
58 |
+
.output {
|
59 |
+
background-color: #5F5F5F;
|
60 |
+
border-radius: 8px;
|
61 |
+
padding: 15px;
|
62 |
+
font-size: 18px;
|
63 |
+
color: #00BFFF;
|
64 |
+
font-weight: bold;
|
65 |
+
text-align: center;
|
66 |
+
}
|
67 |
+
.btn {
|
68 |
+
background-color: #00BFFF;
|
69 |
+
color: white;
|
70 |
+
font-size: 18px;
|
71 |
+
padding: 12px 24px;
|
72 |
+
border-radius: 8px;
|
73 |
+
border: none;
|
74 |
+
cursor: pointer;
|
75 |
+
width: 100%;
|
76 |
+
}
|
77 |
+
.btn:hover {
|
78 |
+
background-color: #008B8B;
|
79 |
+
}
|
80 |
+
footer {
|
81 |
+
margin-top: 40px;
|
82 |
+
text-align: center;
|
83 |
+
font-size: 14px;
|
84 |
+
color: #dcdcdc;
|
85 |
+
}
|
86 |
+
.container {
|
87 |
+
padding: 20px;
|
88 |
+
border-radius: 12px;
|
89 |
+
background-color: #383838;
|
90 |
+
max-width: 500px;
|
91 |
+
margin: auto;
|
92 |
+
}
|
93 |
+
</style>
|
94 |
+
""", unsafe_allow_html=True)
|
95 |
+
|
96 |
+
# Title and Description
|
97 |
+
st.markdown("<div class='header'>🦠 Disease Prediction</div>", unsafe_allow_html=True)
|
98 |
+
st.markdown("<div class='description'>Enter your symptoms, and the model will predict the possible disease based on the provided input.</div>", unsafe_allow_html=True)
|
99 |
+
|
100 |
+
# Input Box and Prediction Button in a centered container
|
101 |
+
with st.container():
|
102 |
+
symptom = st.text_area("Enter symptoms:", height=150, max_chars=500, placeholder="E.g., fever, cough, headache...", key="symptom", label_visibility="collapsed")
|
103 |
+
|
104 |
+
if st.button("Predict", key="predict_button"):
|
105 |
+
if symptom:
|
106 |
+
predicted_disease = predict_disease(symptom)
|
107 |
+
st.markdown(f"<div class='output'>**Predicted Disease: {predicted_disease}**</div>", unsafe_allow_html=True)
|
108 |
+
else:
|
109 |
+
st.warning("Please enter some symptoms to predict the disease.", icon="⚠️")
|
110 |
+
|
111 |
+
# Footer with minimalistic text
|
112 |
+
st.markdown("""
|
113 |
+
<footer>
|
114 |
+
<p>Powered by AI | Developed for Final Year Project </p>
|
115 |
+
</footer>
|
116 |
+
""", unsafe_allow_html=True)
|
knn_model.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:300017d936663b7d98f76e629ff46adb1c2e63332b4792b3194cf3d5ffd9de80
|
3 |
+
size 11076020
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
joblib
|
3 |
+
scikit-learn
|
4 |
+
nltk
|
tfidf_vectorizer.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:334f1610b76e8b40dd348a6b36a0b9cc7a92775a6e80a934ead330fdcb6a769f
|
3 |
+
size 65804
|