File size: 1,597 Bytes
eb87013
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import joblib
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize

# Load the trained KNN model
knn_classifier = joblib.load('knn_model.pkl')

# Load the TF-IDF vectorizer
tfidf_vectorizer = joblib.load('tfidf_vectorizer.pkl')

# Download nltk resources
nltk.download('punkt')
nltk.download('stopwords')

# Text Preprocessing Function
stop_words = set(stopwords.words('english'))

def preprocess_text(text):
    words = word_tokenize(text.lower())
    words = [word for word in words if word.isalpha() and word not in stop_words]
    return ' '.join(words)

# Inference function
def predict_disease(symptom):
    preprocessed_symptom = preprocess_text(symptom)
    symptom_tfidf = tfidf_vectorizer.transform([preprocessed_symptom])
    predicted_disease = knn_classifier.predict(symptom_tfidf)
    return predicted_disease[0]

# Streamlit UI
st.title("Disease Classification using Symptoms")
st.markdown("Enter your symptoms to predict the disease.")

# Input box for symptoms
symptom = st.text_input("Enter symptoms:", "")

# Predict button
if st.button("Predict Disease"):
    if symptom:
        predicted_disease = predict_disease(symptom)
        st.success(f"Predicted Disease: {predicted_disease}")
    else:
        st.warning("Please enter symptoms.")

# Add some styling
st.markdown(
    """
    <style>
    .main .block-container {
        max-width: 600px;
        padding-top: 2rem;
        padding-right: 2rem;
        padding-left: 2rem;
        padding-bottom: 2rem;
    }
    </style>
    """,
    unsafe_allow_html=True
)