disease / app.py
rockerritesh's picture
Update app.py
95854b8 verified
import streamlit as st
import pandas as pd
import plotly.express as px
from streamlit_lottie import st_lottie
import requests
import ast
# Set page config at the very beginning
st.set_page_config(page_title="Health Explorer", page_icon="🩺", layout="wide")
# Function to load Lottie animation
def load_lottieurl(url: str):
r = requests.get(url)
if r.status_code != 200:
return None
return r.json()
# Load DataFrame
@st.cache_data
def load_data():
df = pd.read_csv('disease.csv')
# Convert string representations of lists to actual lists
df['symptom'] = df['symptom'].apply(ast.literal_eval)
df['aurvedic_treatments'] = df['aurvedic_treatments'].apply(ast.literal_eval)
return df
# Load data
df = load_data()
# Sidebar
st.sidebar.title("Health Explorer 🩺")
page = st.sidebar.radio("Navigate", ["Home", "Disease Search", "Statistics"])
if page == "Home":
st.title("Welcome to Health Explorer")
col1, col2 = st.columns([2, 1])
with col1:
st.markdown("""
Explore information about various diseases, their treatments, and prevention methods.
Use the sidebar to navigate through different sections of the app.
- **Disease Search**: Look up specific diseases and get detailed information.
- **Statistics**: View overall statistics about the diseases in our database.
""")
with col2:
lottie_health = load_lottieurl("https://assets1.lottiefiles.com/packages/lf20_5njp3vgg.json")
st_lottie(lottie_health, height=200)
elif page == "Disease Search":
st.title("Disease Information Search")
# Input search query with suggestions from the Disease column
search_query = st.text_input("Start typing a disease name...", "")
# Generate suggestions dynamically based on input
if search_query:
suggestions = df[df['Disease'].str.contains(search_query, case=False)]['Disease'].tolist()
else:
suggestions = df['Disease'].tolist()
# Show suggestions in a selectbox (if suggestions exist)
selected_disease = st.selectbox("Search results:", suggestions)
# If a disease is selected, display the details
if selected_disease:
result = df[df['Disease'] == selected_disease]
for index, row in result.iterrows():
st.header(row['Disease'])
col1, col2 = st.columns(2)
with col1:
st.subheader("Treatment")
st.info(row['treatment'])
st.subheader("Prevention")
st.success(row['prevention'])
with col2:
st.subheader("Symptoms")
for symptom in row['symptom']:
st.warning(f"• {symptom}")
st.subheader("Ayurvedic Treatments")
for treatment in row['aurvedic_treatments']:
st.info(f"• {treatment}")
# Word cloud of symptoms
try:
from wordcloud import WordCloud
import matplotlib.pyplot as plt
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(' '.join(row['symptom']))
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
st.pyplot(plt)
except ImportError:
st.write("Word cloud visualization is not available.")
elif page == "Statistics":
st.title("Disease Statistics")
# Count of diseases by treatment type
treatment_counts = df['treatment'].value_counts()
fig = px.pie(values=treatment_counts.values, names=treatment_counts.index, title="Distribution of Treatment Types")
st.plotly_chart(fig)
# Top 10 most common symptoms
all_symptoms = [symptom for symptoms in df['symptom'] for symptom in symptoms]
symptom_counts = pd.Series(all_symptoms).value_counts().head(10)
fig = px.bar(x=symptom_counts.index, y=symptom_counts.values, title="Top 10 Most Common Symptoms")
fig.update_xaxes(title="Symptom")
fig.update_yaxes(title="Frequency")
st.plotly_chart(fig)
# Footer
st.sidebar.markdown("---")
st.sidebar.info("Created with ❤️ by [Sumit Yadav](sumityadav.com.np)")