ASNVS commited on
Commit
4a591de
·
verified ·
1 Parent(s): 6486f4b

this is the updated code

Browse files
Files changed (1) hide show
  1. app.py +28 -76
app.py CHANGED
@@ -1,12 +1,13 @@
1
  import streamlit as st
2
- from langchain_google_genai import ChatGoogleGenerativeAI
 
3
 
4
- # Set up AI model
5
- llm = ChatGoogleGenerativeAI(
6
- model="gemini-1.5-flash", # Free model
7
- google_api_key="AIzaSyC7Rhv4L6_oNl-nW3Qeku2SPRkxL5hhtoE",
8
- temperature=0.5
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
- # Streamlit UI
40
- st.title("AI-Driven Health Assistant")
41
- st.write("Welcome to the AI-Driven Health Assistant! Simply enter your symptoms or disease name, and get accurate medicine suggestions instantly. Stay informed, stay healthy!")
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
- # Process User Query
58
- if st.button("Get Recommendation"):
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
- with st.spinner("Analyzing..."):
68
- response = llm.invoke(formatted_question)
69
 
70
- response_text = response.content if hasattr(response, "content") else str(response)
71
 
72
- if is_valid_response(response_text):
73
- st.success("✨ Analysis complete! Here are the best medicine recommendations for you: 🔽")
74
- st.write(response_text)
75
- else:
76
- st.warning("⚠️ Oops! It looks like the input is unclear or incorrect. Please enter a valid disease name or symptoms to get accurate recommendations")
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
- if is_valid_response(retry_response_text):
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
- # Emergency Contact Button
98
- if st.button("Emergency Contact"):
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
- # Footer
106
- st.markdown("---")
 
 
 
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]}')