| | import os |
| | import streamlit as st |
| | from groq import Groq |
| | from dotenv import load_dotenv |
| |
|
| | |
| | load_dotenv() |
| | GROQ_API_KEY = os.getenv("GROQ_API_KEY") |
| | if not GROQ_API_KEY: |
| | st.error("GROQ API Key not found. Please set the API key in a .env file and restart the app.") |
| | st.stop() |
| |
|
| | |
| | client = Groq(api_key=GROQ_API_KEY) |
| |
|
| | |
| | topic_responses = { |
| | "fever": "For fever, take paracetamol and stay hydrated. If symptoms persist, consult a doctor.", |
| | "malaria": "For malaria, take prescribed antimalarial drugs and rest. Visit a doctor for proper diagnosis.", |
| | "flu": "For flu, take antihistamines, drink warm fluids, and rest. Consider over-the-counter pain relievers.", |
| | "cough": "For cough, drink warm honey tea, use cough syrup, and avoid cold drinks. If severe, see a doctor.", |
| | "typhoid": "For typhoid, take antibiotics as prescribed by a doctor and maintain good hydration. Avoid contaminated food." |
| | } |
| |
|
| | def get_health_advice(user_input): |
| | user_input = user_input.lower() |
| | for topic, response in topic_responses.items(): |
| | if topic in user_input: |
| | return response |
| | return "Sorry, I don't have knowledge about that. Ask me only health-related matters." |
| |
|
| | |
| | st.title("Health Assistance Chatbot") |
| | st.write("Ask about Fever, Malaria, Flu, Cough, or Typhoid for symptoms and treatment suggestions.") |
| |
|
| | |
| | if "messages" not in st.session_state: |
| | st.session_state.messages = [] |
| |
|
| | |
| | for message in st.session_state.messages: |
| | with st.chat_message(message["role"]): |
| | st.markdown(message["content"]) |
| |
|
| | |
| | user_input = st.chat_input("Type your question here...") |
| | if user_input: |
| | st.session_state.messages.append({"role": "user", "content": user_input}) |
| | |
| | |
| | bot_response = get_health_advice(user_input) |
| | |
| | |
| | st.session_state.messages.append({"role": "assistant", "content": bot_response}) |
| | |
| | |
| | with st.chat_message("assistant"): |
| | st.markdown(bot_response) |
| |
|