Dua Rajper commited on
Commit
2dd08e5
·
verified ·
1 Parent(s): 9ec99db

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
9
+ if not GROQ_API_KEY:
10
+ st.error("GROQ API Key not found. Please set the API key in a .env file and restart the app.")
11
+ st.stop()
12
+
13
+ # Initialize Groq client
14
+ client = Groq(api_key=GROQ_API_KEY)
15
+
16
+ # Define allowed health topics
17
+ topic_responses = {
18
+ "fever": "For fever, take paracetamol and stay hydrated. If symptoms persist, consult a doctor.",
19
+ "malaria": "For malaria, take prescribed antimalarial drugs and rest. Visit a doctor for proper diagnosis.",
20
+ "flu": "For flu, take antihistamines, drink warm fluids, and rest. Consider over-the-counter pain relievers.",
21
+ "cough": "For cough, drink warm honey tea, use cough syrup, and avoid cold drinks. If severe, see a doctor.",
22
+ "typhoid": "For typhoid, take antibiotics as prescribed by a doctor and maintain good hydration. Avoid contaminated food."
23
+ }
24
+
25
+ def get_health_advice(user_input):
26
+ user_input = user_input.lower()
27
+ for topic, response in topic_responses.items():
28
+ if topic in user_input:
29
+ return response
30
+ return "Sorry, I don't have knowledge about that. Ask me only health-related matters."
31
+
32
+ # Streamlit UI setup
33
+ st.title("Health Assistance Chatbot")
34
+ st.write("Ask about Fever, Malaria, Flu, Cough, or Typhoid for symptoms and treatment suggestions.")
35
+
36
+ # Store chat history
37
+ if "messages" not in st.session_state:
38
+ st.session_state.messages = []
39
+
40
+ # Display chat history
41
+ for message in st.session_state.messages:
42
+ with st.chat_message(message["role"]):
43
+ st.markdown(message["content"])
44
+
45
+ # User input
46
+ user_input = st.chat_input("Type your question here...")
47
+ if user_input:
48
+ st.session_state.messages.append({"role": "user", "content": user_input})
49
+
50
+ # Check if input is health-related
51
+ bot_response = get_health_advice(user_input)
52
+
53
+ # Append bot response to chat history
54
+ st.session_state.messages.append({"role": "assistant", "content": bot_response})
55
+
56
+ # Display bot response
57
+ with st.chat_message("assistant"):
58
+ st.markdown(bot_response)