farsim/dr_aida
0
1import streamlit as st
2from chatbot_logic import chat_with_mistral
3from disease_prediction import predict_disease, get_drug_recommendations
4import pandas as pd
5
6# Load your drugs dataframe
7drugs_df = pd.read_csv('drugs_df_combined.csv') # Replace with actual path
8
9# Initialize session state variables
10if 'messages' not in st.session_state:
11 st.session_state.messages = []
12if 'name' not in st.session_state:
13 st.session_state.name = None
14
15st.title("Dr. Aida - Your AI Health Assistant")
16
17# Get user's name if not already provided
18if not st.session_state.name:
19 st.session_state.name = st.text_input("Please enter your name:")
20 if st.session_state.name:
21 st.session_state.messages.append({"role": "assistant", "content": f"Nice to meet you, {st.session_state.name}. How are you feeling today?"})
22
23# Display chat messages
24for message in st.session_state.messages:
25 with st.chat_message(message["role"]):
26 st.markdown(message["content"])
27
28# Chat input
29# Chat input
30if st.session_state.name:
31 user_input = st.chat_input("Type your symptoms here...")
32
33 if user_input:
34 # Add user message to chat history
35 st.session_state.messages.append({"role": "user", "content": user_input})
36
37 if user_input.lower() == "no more symptoms":
38 # Predict disease
39 predicted_disease = predict_disease(st.session_state.messages)
40
41 if predicted_disease:
42 # Get drug recommendations
43 recommended_drugs = get_drug_recommendations(predicted_disease, drugs_df)
44
45 # Prepare the response
46 final_response = f"Based on the symptoms you've described, you may have: {predicted_disease}."
47
48 if recommended_drugs:
49 drug_list = ", ".join(recommended_drugs[:5])
50 final_response += f" You can consider taking these medicines: {drug_list}. However, please consult with a healthcare professional before taking any medication."
51 else:
52 final_response += " I couldn't find specific medication recommendations for this condition in my database. Please consult with a healthcare professional for appropriate treatment."
53
54 final_response += "\n\n\nYou can also contact our 24/7 appointment desk to get an appointment with our healthcare professionals. Call us at 400-500-SICK for the appointment. Thank you and hope you feel better soon."
55
56 # Add final response to chat history
57 st.session_state.messages.append({"role": "assistant", "content": final_response})
58 else:
59 st.session_state.messages.append({"role": "assistant", "content": "I'm sorry, but I couldn't determine a specific condition based on the symptoms you've described. It's best to consult with a healthcare professional for a proper diagnosis and treatment plan."})
60 else:
61 # Get chatbot response for ongoing symptom description
62 response, _ = chat_with_mistral(user_input, st.session_state.messages, st.session_state.name)
63
64 # Add assistant message to chat history
65 st.session_state.messages.append({"role": "assistant", "content": response})
66
67 # Rerun the app to display the new messages
68 st.rerun()
69
70
71# Add a disclaimer at the bottom of the page
72st.markdown("---")
73st.markdown("**Disclaimer:** This AI health assistant is for informational purposes only and is not a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition.")
74 