File size: 3,476 Bytes
75d91b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import streamlit as st
import joblib
import re
import string

# Load the trained model and TF-IDF vectorizer
knn_model = joblib.load('knn_model.joblib')
tfidf_vectorizer = joblib.load('tfidf_vectorizer.joblib')

# Preprocess the input text (same preprocessing as in the notebook)
def preprocess_text(text):
    text = text.lower()  # Convert to lowercase
    text = re.sub(r'\d+', '', text)  # Remove digits
    text = text.translate(str.maketrans('', '', string.punctuation))  # Remove punctuation
    return text

# Prediction function
def predict_disease(symptom):
    preprocessed_symptom = preprocess_text(symptom)
    tfidf_features = tfidf_vectorizer.transform([preprocessed_symptom]).toarray()
    predicted_disease = knn_model.predict(tfidf_features)
    return predicted_disease[0]

# Streamlit UI Design
st.set_page_config(page_title="Disease Prediction App", page_icon="🦠", layout="centered")

# Custom Styling
st.markdown("""
    <style>
    body {
        background-color: #2E2E2E;
        color: white;
        font-family: 'Segoe UI', sans-serif;
    }
    .header {
        font-size: 36px;
        font-weight: bold;
        color: #00BFFF;
        text-align: center;
        margin-top: 30px;
        margin-bottom: 15px;
    }
    .description {
        font-size: 16px;
        color: #dcdcdc;
        text-align: center;
        margin-bottom: 20px;
    }
    .input-box {
        background-color: #3E3E3E;
        border-radius: 8px;
        padding: 15px;
        font-size: 16px;
        font-family: 'Segoe UI', sans-serif;
        border: none;
        color: white;
    }
    .output {
        background-color: #5F5F5F;
        border-radius: 8px;
        padding: 15px;
        font-size: 18px;
        color: #00BFFF;
        font-weight: bold;
        text-align: center;
    }
    .btn {
        background-color: #00BFFF;
        color: white;
        font-size: 18px;
        padding: 12px 24px;
        border-radius: 8px;
        border: none;
        cursor: pointer;
        width: 100%;
    }
    .btn:hover {
        background-color: #008B8B;
    }
    footer {
        margin-top: 40px;
        text-align: center;
        font-size: 14px;
        color: #dcdcdc;
    }
    .container {
        padding: 20px;
        border-radius: 12px;
        background-color: #383838;
        max-width: 500px;
        margin: auto;
    }
    </style>
""", unsafe_allow_html=True)

# Title and Description
st.markdown("<div class='header'>🦠 Disease Prediction</div>", unsafe_allow_html=True)
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)

# Input Box and Prediction Button in a centered container
with st.container():
    symptom = st.text_area("Enter symptoms:", height=150, max_chars=500, placeholder="E.g., fever, cough, headache...", key="symptom", label_visibility="collapsed")
    
    if st.button("Predict", key="predict_button"):
        if symptom:
            predicted_disease = predict_disease(symptom)
            st.markdown(f"<div class='output'>**Predicted Disease: {predicted_disease}**</div>", unsafe_allow_html=True)
        else:
            st.warning("Please enter some symptoms to predict the disease.", icon="⚠️")

# Footer with minimalistic text
st.markdown("""
    <footer>
        <p>Powered by AI | Developed for Final Year Project </p>
    </footer>
""", unsafe_allow_html=True)