this is the updated code
Browse files
app.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
)
|
| 10 |
|
| 11 |
# Custom CSS for background color and text color
|
| 12 |
st.markdown(
|
|
@@ -16,91 +17,42 @@ st.markdown(
|
|
| 16 |
background-color: #efefef !important;
|
| 17 |
color: black !important;
|
| 18 |
}
|
| 19 |
-
iframe {
|
| 20 |
-
border: none !important;
|
| 21 |
-
box-shadow: none !important;
|
| 22 |
-
outline: none !important;
|
| 23 |
-
}
|
| 24 |
h1, h2, h3, h4, h5, h6, p, div, span, label {
|
| 25 |
color: black !important;
|
| 26 |
}
|
| 27 |
button, .stButton>button {
|
| 28 |
color: black !important;
|
| 29 |
-
background-color: grey !important;
|
| 30 |
}
|
| 31 |
-
/* Hide Streamlit's top colored bar and options icon */
|
| 32 |
header {display: none !important;}
|
| 33 |
-
.stDeployButton {display: none !important;}
|
| 34 |
</style>
|
| 35 |
""",
|
| 36 |
unsafe_allow_html=True
|
| 37 |
)
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
st.
|
| 41 |
-
st.
|
| 42 |
-
|
| 43 |
-
# User Input
|
| 44 |
-
user_question = st.text_input("Type your symptoms or disease name, and let CureBot unlock the right cure for you—fast, smart, and AI-powered")
|
| 45 |
-
|
| 46 |
-
# Function to filter AI disclaimers
|
| 47 |
-
def is_valid_response(response_text):
|
| 48 |
-
disclaimers = [
|
| 49 |
-
"I am an AI and cannot give medical advice",
|
| 50 |
-
"Seek medical attention",
|
| 51 |
-
"Consult a doctor",
|
| 52 |
-
"Contact your doctor",
|
| 53 |
-
"Go to an emergency room",
|
| 54 |
-
]
|
| 55 |
-
return not any(phrase.lower() in response_text.lower() for phrase in disclaimers)
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
if user_question.strip():
|
| 60 |
-
formatted_question = (
|
| 61 |
-
f"Without any disclaimer, recommend medicine for {user_question}. "
|
| 62 |
-
f"5 medicine names "
|
| 63 |
-
f"Also, provide alternative treatments such as home remedies, lifestyle changes, exercises, or dietary suggestions. "
|
| 64 |
-
f"Only for learning purposes, not for treatment."
|
| 65 |
-
)
|
| 66 |
|
| 67 |
-
|
| 68 |
-
response = llm.invoke(formatted_question)
|
| 69 |
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
better_prompt = (
|
| 78 |
-
f"Strictly provide a detailed answer including:\n"
|
| 79 |
-
f"1. Medicine names\n"
|
| 80 |
-
f"2. Home remedies\n"
|
| 81 |
-
f"3. Lifestyle changes\n"
|
| 82 |
-
f"4. Exercises\n"
|
| 83 |
-
f"5. Diet recommendations\n"
|
| 84 |
-
f"Do not include any disclaimers. The response should be clear and structured."
|
| 85 |
-
)
|
| 86 |
-
retry_response = llm.invoke(better_prompt)
|
| 87 |
-
retry_response_text = retry_response.content if hasattr(retry_response, "content") else str(retry_response)
|
| 88 |
|
| 89 |
-
|
| 90 |
-
st.success("Here is the refined information:")
|
| 91 |
-
st.write(retry_response_text)
|
| 92 |
-
else:
|
| 93 |
-
st.error("Unable to get a useful response. Try rephrasing your question.")
|
| 94 |
-
else:
|
| 95 |
-
st.warning("Please enter a question!")
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
st.subheader("📞 Emergency Contacts")
|
| 100 |
-
st.write("- 🚑 *Ambulance:* 102")
|
| 101 |
-
st.write("- 🏥 *National Health Helpline:* 108")
|
| 102 |
-
st.write("- ☎ *COVID-19 Helpline:* 1075")
|
| 103 |
-
st.write("- 🚓 *Police:* 100")
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from code.DiseaseModel import DiseaseModel
|
| 3 |
+
from code.helper import prepare_symptoms_array
|
| 4 |
|
| 5 |
+
# Create disease class and load ML model
|
| 6 |
+
disease_model = DiseaseModel()
|
| 7 |
+
disease_model.load_xgboost('model/xgboost_model.json')
|
| 8 |
+
|
| 9 |
+
# Set page width to wide
|
| 10 |
+
st.set_page_config(layout='wide')
|
| 11 |
|
| 12 |
# Custom CSS for background color and text color
|
| 13 |
st.markdown(
|
|
|
|
| 17 |
background-color: #efefef !important;
|
| 18 |
color: black !important;
|
| 19 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
h1, h2, h3, h4, h5, h6, p, div, span, label {
|
| 21 |
color: black !important;
|
| 22 |
}
|
| 23 |
button, .stButton>button {
|
| 24 |
color: black !important;
|
|
|
|
| 25 |
}
|
|
|
|
| 26 |
header {display: none !important;}
|
|
|
|
| 27 |
</style>
|
| 28 |
""",
|
| 29 |
unsafe_allow_html=True
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# Create sidebar
|
| 33 |
+
st.sidebar.markdown('# The Health AI ')
|
| 34 |
+
st.sidebar.markdown("This web app uses a machine learning model to predict diseases based on a set of symptoms using Scikit-learn, Python and Streamlit.")
|
| 35 |
+
st.sidebar.markdown("Author: S N V S KOMAL")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
# Title
|
| 38 |
+
st.write('# Symptoms to Disease Prediction')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
symptoms = st.multiselect('What are your symptoms?', options=disease_model.all_symptoms)
|
|
|
|
| 41 |
|
| 42 |
+
X = prepare_symptoms_array(symptoms)
|
| 43 |
|
| 44 |
+
# Trigger XGBoost model
|
| 45 |
+
if st.button('Predict'):
|
| 46 |
+
# Run the model with the python script
|
| 47 |
+
prediction, prob = disease_model.predict(X)
|
| 48 |
+
st.write(f'## Disease: {prediction} with {prob*100:.2f}% probability')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
tab1, tab2= st.tabs(["Description", "Precautions"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
with tab1:
|
| 53 |
+
st.write(disease_model.describe_predicted_disease())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
with tab2:
|
| 56 |
+
precautions = disease_model.predicted_disease_precautions()
|
| 57 |
+
for i in range(4):
|
| 58 |
+
st.write(f'{i+1}. {precautions[i]}')
|