MayankGupta06 commited on
Commit
16561ba
Β·
verified Β·
1 Parent(s): b807cd3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -80
app.py CHANGED
@@ -243,96 +243,96 @@
243
 
244
 
245
  #------------------------------------------------------------------------start
246
- import streamlit as st
247
- from langchain_google_genai import ChatGoogleGenerativeAI
248
 
249
- # Set up AI model
250
- llm = ChatGoogleGenerativeAI(
251
- model="gemini-1.5-flash", # Free model
252
- google_api_key="AIzaSyC7Rhv4L6_oNl-nW3Qeku2SPRkxL5hhtoE",
253
- temperature=0.5
254
- )
255
 
256
- # Streamlit UI
257
- st.title("🩺 CureBot: AI-Driven Health Assistant")
258
- st.write("Welcome to CureBot – Your AI-Driven Health Assistant! Simply enter your symptoms or disease name, and get accurate medicine suggestions instantly. Stay informed, stay healthy!")
259
-
260
- # User Input
261
- 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")
262
-
263
- # Function to filter AI disclaimers
264
- def is_valid_response(response_text):
265
- disclaimers = [
266
- "I am an AI and cannot give medical advice",
267
- "Seek medical attention",
268
- "Consult a doctor",
269
- "Contact your doctor",
270
- "Go to an emergency room",
271
  ]
272
- return not any(phrase.lower() in response_text.lower() for phrase in disclaimers)
273
-
274
- # Process User Query
275
- if st.button("Get Recommendation"):
276
- if user_question.strip():
277
- # Ensure the AI provides both medicine and alternative treatments
278
- formatted_question = (
279
- f"Without any disclaimer, recommend medicine for {user_question}. "
280
- f"5 medicine names "
281
- f"Also, provide alternative treatments such as home remedies, lifestyle changes, exercises, or dietary suggestions. "
282
- f"Only for learning purposes, not for treatment."
283
- )
284
-
285
- with st.spinner("Analyzing..."):
286
- response = llm.invoke(formatted_question)
287
-
288
- # Extract text content
289
- response_text = response.content if hasattr(response, "content") else str(response)
290
-
291
- # Check if response is valid
292
- if is_valid_response(response_text):
293
- st.success("✨ Analysis complete! Here are the best medicine recommendations for you: πŸ”½")
294
- st.write(response_text)
295
- else:
296
- st.warning("⚠️ Oops! It looks like the input is unclear or incorrect. Please enter a valid disease name or symptoms to get accurate recommendations")
297
- # Retry with a refined prompt
298
- better_prompt = (
299
- f"Strictly provide a detailed answer including:\n"
300
- f"1. Medicine names\n"
301
- f"2. Home remedies\n"
302
- f"3. Lifestyle changes\n"
303
- f"4. Exercises\n"
304
- f"5. Diet recommendations\n"
305
- f"Do not include any disclaimers. The response should be clear and structured."
306
- )
307
- retry_response = llm.invoke(better_prompt)
308
 
309
- # Extract text from retry response
310
- retry_response_text = retry_response.content if hasattr(retry_response, "content") else str(retry_response)
 
 
 
 
 
 
 
 
311
 
312
- # Display the retried response if valid
313
- if is_valid_response(retry_response_text):
314
- st.success("Here is the refined information:")
315
- st.write(retry_response_text)
316
- else:
317
- st.error("Unable to get a useful response. Try rephrasing your question.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
 
319
- else:
320
- st.warning("Please enter a question!")
321
 
322
 
323
- # Emergency Contact Button
324
- if st.button("Emergency Contact"):
325
- st.subheader("πŸ“ž Emergency Contacts")
326
- st.write("- πŸš‘ *Ambulance:* 102")
327
- st.write("- πŸ₯ *LPU Hospital:* 18001024432")
328
- st.write("- πŸ₯ *National Health Helpline:* 108")
329
- st.write("- ☎ *COVID-19 Helpline:* 1075")
330
- st.write("- πŸš“ *Police:* 100")
331
 
332
- # Footer
333
- st.markdown("---")
334
 
335
- st.markdown("πŸ”Ή Powered by Mayank, Wasim, Pravishank – Innovating Healthcare with AI! πŸ’‘ Your Health, Our Mission. πŸš€")
336
 
337
 
338
 
 
243
 
244
 
245
  #------------------------------------------------------------------------start
246
+ # import streamlit as st
247
+ # from langchain_google_genai import ChatGoogleGenerativeAI
248
 
249
+ # # Set up AI model
250
+ # llm = ChatGoogleGenerativeAI(
251
+ # model="gemini-1.5-flash", # Free model
252
+ # google_api_key="AIzaSyC7Rhv4L6_oNl-nW3Qeku2SPRkxL5hhtoE",
253
+ # temperature=0.5
254
+ # )
255
 
256
+ # # Streamlit UI
257
+ # st.title("🩺 CureBot: AI-Driven Health Assistant")
258
+ # st.write("Welcome to CureBot – Your AI-Driven Health Assistant! Simply enter your symptoms or disease name, and get accurate medicine suggestions instantly. Stay informed, stay healthy!")
259
+
260
+ # # User Input
261
+ # 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")
262
+
263
+ # # Function to filter AI disclaimers
264
+ # def is_valid_response(response_text):
265
+ # disclaimers = [
266
+ # "I am an AI and cannot give medical advice",
267
+ # "Seek medical attention",
268
+ # "Consult a doctor",
269
+ # "Contact your doctor",
270
+ # "Go to an emergency room",
271
  ]
272
+ # return not any(phrase.lower() in response_text.lower() for phrase in disclaimers)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
 
274
+ # # Process User Query
275
+ # if st.button("Get Recommendation"):
276
+ # if user_question.strip():
277
+ # # Ensure the AI provides both medicine and alternative treatments
278
+ # formatted_question = (
279
+ # f"Without any disclaimer, recommend medicine for {user_question}. "
280
+ # f"5 medicine names "
281
+ # f"Also, provide alternative treatments such as home remedies, lifestyle changes, exercises, or dietary suggestions. "
282
+ # f"Only for learning purposes, not for treatment."
283
+ # )
284
 
285
+ # with st.spinner("Analyzing..."):
286
+ # # response = llm.invoke(formatted_question)
287
+
288
+ # # Extract text content
289
+ # response_text = response.content if hasattr(response, "content") else str(response)
290
+
291
+ # # Check if response is valid
292
+ # if is_valid_response(response_text):
293
+ # st.success("✨ Analysis complete! Here are the best medicine recommendations for you: πŸ”½")
294
+ # st.write(response_text)
295
+ # else:
296
+ # st.warning("⚠️ Oops! It looks like the input is unclear or incorrect. Please enter a valid disease name or symptoms to get accurate recommendations")
297
+ # # Retry with a refined prompt
298
+ # better_prompt = (
299
+ # f"Strictly provide a detailed answer including:\n"
300
+ # f"1. Medicine names\n"
301
+ # f"2. Home remedies\n"
302
+ # f"3. Lifestyle changes\n"
303
+ # f"4. Exercises\n"
304
+ # f"5. Diet recommendations\n"
305
+ # f"Do not include any disclaimers. The response should be clear and structured."
306
+ # )
307
+ # retry_response = llm.invoke(better_prompt)
308
+
309
+ # # Extract text from retry response
310
+ # retry_response_text = retry_response.content if hasattr(retry_response, "content") else str(retry_response)
311
+
312
+ # # Display the retried response if valid
313
+ # if is_valid_response(retry_response_text):
314
+ # st.success("Here is the refined information:")
315
+ # st.write(retry_response_text)
316
+ # else:
317
+ # st.error("Unable to get a useful response. Try rephrasing your question.")
318
 
319
+ # else:
320
+ # st.warning("Please enter a question!")
321
 
322
 
323
+ # # Emergency Contact Button
324
+ # if st.button("Emergency Contact"):
325
+ # st.subheader("πŸ“ž Emergency Contacts")
326
+ # st.write("- πŸš‘ *Ambulance:* 102")
327
+ # st.write("- πŸ₯ *LPU Hospital:* 18001024432")
328
+ # st.write("- πŸ₯ *National Health Helpline:* 108")
329
+ # st.write("- ☎ *COVID-19 Helpline:* 1075")
330
+ # st.write("- πŸš“ *Police:* 100")
331
 
332
+ # # Footer
333
+ # st.markdown("---")
334
 
335
+ # st.markdown("πŸ”Ή Powered by Mayank, Wasim, Pravishank – Innovating Healthcare with AI! πŸ’‘ Your Health, Our Mission. πŸš€")
336
 
337
 
338