rajsecrets0 commited on
Commit
eb87013
·
verified ·
1 Parent(s): 401ab56

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import joblib
3
+ import nltk
4
+ from nltk.corpus import stopwords
5
+ from nltk.tokenize import word_tokenize
6
+
7
+ # Load the trained KNN model
8
+ knn_classifier = joblib.load('knn_model.pkl')
9
+
10
+ # Load the TF-IDF vectorizer
11
+ tfidf_vectorizer = joblib.load('tfidf_vectorizer.pkl')
12
+
13
+ # Download nltk resources
14
+ nltk.download('punkt')
15
+ nltk.download('stopwords')
16
+
17
+ # Text Preprocessing Function
18
+ stop_words = set(stopwords.words('english'))
19
+
20
+ def preprocess_text(text):
21
+ words = word_tokenize(text.lower())
22
+ words = [word for word in words if word.isalpha() and word not in stop_words]
23
+ return ' '.join(words)
24
+
25
+ # Inference function
26
+ def predict_disease(symptom):
27
+ preprocessed_symptom = preprocess_text(symptom)
28
+ symptom_tfidf = tfidf_vectorizer.transform([preprocessed_symptom])
29
+ predicted_disease = knn_classifier.predict(symptom_tfidf)
30
+ return predicted_disease[0]
31
+
32
+ # Streamlit UI
33
+ st.title("Disease Classification using Symptoms")
34
+ st.markdown("Enter your symptoms to predict the disease.")
35
+
36
+ # Input box for symptoms
37
+ symptom = st.text_input("Enter symptoms:", "")
38
+
39
+ # Predict button
40
+ if st.button("Predict Disease"):
41
+ if symptom:
42
+ predicted_disease = predict_disease(symptom)
43
+ st.success(f"Predicted Disease: {predicted_disease}")
44
+ else:
45
+ st.warning("Please enter symptoms.")
46
+
47
+ # Add some styling
48
+ st.markdown(
49
+ """
50
+ <style>
51
+ .main .block-container {
52
+ max-width: 600px;
53
+ padding-top: 2rem;
54
+ padding-right: 2rem;
55
+ padding-left: 2rem;
56
+ padding-bottom: 2rem;
57
+ }
58
+ </style>
59
+ """,
60
+ unsafe_allow_html=True
61
+ )