Rajesh2004's picture
Upload 6 files
e18a53b verified
import streamlit as st
import pandas as pd
import joblib
import spacy
import subprocess
# Install spaCy model if not already installed
try:
nlp = spacy.load("en_core_web_sm")
except OSError:
st.warning("Downloading spaCy model 'en_core_web_sm'... This may take a few minutes.")
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
nlp = spacy.load("en_core_web_sm")
# Load the trained model
model = joblib.load("disease_model.pkl")
# Load dataset for additional details
df = pd.read_csv("disease_dataset.csv")
def preprocess_input(symptoms):
"""Preprocess user input using spaCy."""
doc = nlp(symptoms)
tokens = [token.lemma_.lower() for token in doc if not token.is_stop and not token.is_punct]
return " ".join(tokens)
def predict_disease(symptoms):
"""Predict disease based on symptoms."""
processed_input = preprocess_input(symptoms)
prediction = model.predict([processed_input])
return prediction[0]
def get_disease_details(disease):
"""Get additional details about the disease."""
details = df[df["disease"] == disease].iloc[0]
return details
# Streamlit app
st.title("Medical Chatbot for Symptom Analysis")
st.write("Enter your symptoms below to get a possible diagnosis and recommendations.")
# User input
symptoms = st.text_input("Enter your symptoms (comma-separated):")
if st.button("Analyze Symptoms"):
if symptoms:
# Predict disease
disease = predict_disease(symptoms)
st.success(f"Predicted Disease: **{disease}**")
# Get additional details
details = get_disease_details(disease)
st.subheader("Details:")
st.write(f"**Cures:** {details['cures']}")
st.write(f"**Recommended Doctor:** {details['doctor']}")
st.write(f"**Risk Level:** {details['risk level']}")
else:
st.error("Please enter symptoms to analyze.")