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(""" """, unsafe_allow_html=True) # Title and Description st.markdown("
🦠 Disease Prediction
", unsafe_allow_html=True) st.markdown("
Enter your symptoms, and the model will predict the possible disease based on the provided input.
", 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"
**Predicted Disease: {predicted_disease}**
", unsafe_allow_html=True) else: st.warning("Please enter some symptoms to predict the disease.", icon="⚠️") # Footer with minimalistic text st.markdown(""" """, unsafe_allow_html=True)