ASNVS commited on
Commit
0faa73c
·
verified ·
1 Parent(s): fa7d26f
Files changed (1) hide show
  1. app.py +1 -167
app.py CHANGED
@@ -1,170 +1,3 @@
1
-
2
-
3
- # # # # Process User Query
4
- # # # if st.button("Get Information"):
5
- # # # if user_question.strip():
6
- # # # with st.spinner("Analyzing..."):
7
- # # # response = llm.invoke(user_question)
8
-
9
- # # # # Check if response is valid
10
- # # # if is_valid_response(response):
11
- # # # st.success("Here is the relevant information:")
12
- # # # st.write(response)
13
- # # # else:
14
- # # # st.warning("AI provided a disclaimer. Trying again...")
15
- # # # # Modify prompt to avoid disclaimers
16
- # # # better_prompt = f"Give a well-explained answer for educational purposes only: {user_question}"
17
- # # # retry_response = llm.invoke(better_prompt)
18
-
19
- # # # # Display the retried response if it's valid
20
- # # # if is_valid_response(retry_response):
21
- # # # st.success("Here is the refined information:")
22
- # # # st.write(retry_response)
23
- # # # else:
24
- # # # st.error("Unable to get a useful response. Try rephrasing your question.")
25
-
26
- # # # else:
27
- # # # st.warning("Please enter a question!")
28
-
29
- # # # # Footer
30
- # # # st.markdown("---")
31
- # # # st.markdown("💡 *This AI provides learning-based medical insights, not actual medical advice.*")
32
-
33
-
34
-
35
- # # import streamlit as st
36
- # # from langchain_google_genai import ChatGoogleGenerativeAI
37
-
38
- # # # Set up AI model
39
- # # llm = ChatGoogleGenerativeAI(
40
- # # model="gemini-1.5-flash", # Free model
41
- # # google_api_key="AIzaSyC7Rhv4L6_oNl-nW3Qeku2SPRkxL5hhtoE",
42
- # # temperature=0.5
43
- # # )
44
-
45
- # # # Streamlit UI
46
- # # st.title("🩺 AI Healthcare Learning Assistant")
47
- # # st.write("Ask me anything about healthcare, symptoms, diet, or medical learning!")
48
-
49
- # # # User Input
50
- # # user_question = st.text_input("Enter your healthcare question:")
51
-
52
- # # # Function to filter AI disclaimers
53
- # # def is_valid_response(response_text):
54
- # # disclaimers = [
55
- # # "I am an AI and cannot give medical advice",
56
- # # "Seek medical attention",
57
- # # "Consult a doctor",
58
- # # "Contact your doctor",
59
- # # "Go to an emergency room",
60
- # # ]
61
- # # return not any(phrase.lower() in response_text.lower() for phrase in disclaimers)
62
-
63
- # # # Process User Query
64
- # # if st.button("Get Information"):
65
- # # if user_question.strip():
66
- # # with st.spinner("Analyzing..."):
67
- # # response = llm.invoke(user_question)
68
-
69
- # # # Extract the text content from AIMessage
70
- # # response_text = response.content if hasattr(response, "content") else str(response)
71
-
72
- # # # Check if response is valid
73
- # # if is_valid_response(response_text):
74
- # # st.success("Here is the relevant information:")
75
- # # st.write(response_text)
76
- # # else:
77
- # # st.warning("AI provided a disclaimer. Trying again...")
78
- # # # Modify prompt to avoid disclaimers
79
- # # better_prompt = f"Give a well-explained answer for educational purposes only: {user_question}"
80
- # # retry_response = llm.invoke(better_prompt)
81
-
82
- # # # Extract text from the retried response
83
- # # retry_response_text = retry_response.content if hasattr(retry_response, "content") else str(retry_response)
84
-
85
- # # # Display the retried response if it's valid
86
- # # if is_valid_response(retry_response_text):
87
- # # st.success("Here is the refined information:")
88
- # # st.write(retry_response_text)
89
- # # else:
90
- # # st.error("Unable to get a useful response. Try rephrasing your question.")
91
-
92
- # # else:
93
- # # st.warning("Please enter a question!")
94
-
95
- # # # Footer
96
- # # st.markdown("---")
97
- # # st.markdown("💡 *This AI provides learning-based medical insights, not actual medical advice.*")
98
-
99
-
100
-
101
-
102
- # import streamlit as st
103
- # from langchain_google_genai import ChatGoogleGenerativeAI
104
-
105
- # # Set up AI model
106
- # llm = ChatGoogleGenerativeAI(
107
- # model="gemini-1.5-flash", # Free model
108
- # google_api_key="AIzaSyC7Rhv4L6_oNl-nW3Qeku2SPRkxL5hhtoE",
109
- # temperature=0.5
110
- # )
111
-
112
- # # Streamlit UI
113
- # st.title("🩺 AI Healthcare Learning Assistant")
114
- # st.write("Ask about symptoms, medicines, and alternative treatments.")
115
-
116
- # # User Input
117
- # user_question = st.text_input("Enter your health-related query:")
118
-
119
- # # Function to filter AI disclaimers
120
- # def is_valid_response(response_text):
121
- # disclaimers = [
122
- # "I am an AI and cannot give medical advice",
123
- # "Seek medical attention",
124
- # "Consult a doctor",
125
- # "Contact your doctor",
126
- # "Go to an emergency room",
127
- # ]
128
- # return not any(phrase.lower() in response_text.lower() for phrase in disclaimers)
129
-
130
- # # Process User Query
131
- # if st.button("Get Recommendation"):
132
- # if user_question.strip():
133
- # # Modify user input to ensure the model focuses on learning-based insights
134
- # formatted_question = f"Without any disclaimer, recommend me medicine for {user_question}. Only for learning purposes, not for treatment. Also, suggest some different ways to cure it."
135
-
136
- # with st.spinner("Analyzing..."):
137
- # response = llm.invoke(formatted_question)
138
-
139
- # # Extract text content
140
- # response_text = response.content if hasattr(response, "content") else str(response)
141
-
142
- # # # Check if response is valid
143
- # if is_valid_response(response_text):
144
- # st.success("Here is the relevant information:")
145
- # st.write(response_text)
146
- # else:
147
- # st.warning("AI provided a disclaimer. Trying again...")
148
- # # Retry with a refined prompt
149
- # better_prompt = f"Its only for leaning purpose not for treatment provide medicine names and alternative treatments for: {user_question}"
150
- # retry_response = llm.invoke(better_prompt)
151
-
152
- # # Extract text from retry response
153
- # retry_response_text = retry_response.content if hasattr(retry_response, "content") else str(retry_response)
154
-
155
- # # # Display the retried response if valid
156
- # # if is_valid_response(retry_response_text):
157
- # # st.success("Here is the refined information:")
158
- # # st.write(retry_response_text)
159
- # # else:
160
- # # st.error("Unable to get a useful response. Try rephrasing your question.")
161
-
162
- # else:
163
- # st.warning("Please enter a question!")
164
-
165
- # # Footer
166
- # st.markdown("---")
167
- # st.markdown("💡 *This AI provides learning-based medical insights, not actual medical advice.*")
168
  import streamlit as st
169
  from langchain_google_genai import ChatGoogleGenerativeAI
170
 
@@ -191,6 +24,7 @@ st.markdown(
191
  }
192
  button, .stButton>button {
193
  color: black !important;
 
194
  }
195
  </style>
196
  """,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from langchain_google_genai import ChatGoogleGenerativeAI
3
 
 
24
  }
25
  button, .stButton>button {
26
  color: black !important;
27
+ background-color: blue !important;
28
  }
29
  </style>
30
  """,