Arshad112 commited on
Commit
a71309a
·
verified ·
1 Parent(s): 8ba062f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -32
app.py CHANGED
@@ -1,37 +1,46 @@
1
  import os
2
  import streamlit as st
3
  from groq import Groq
 
4
 
5
- # Load the API key from the environment
 
 
 
6
  api_key = os.getenv("GROQ_API_KEY")
7
- client = Groq(api_key=api_key)
8
-
9
- # Function to call the Groq API and get the chatbot response
10
- def get_chat_response(query):
11
- chat_completion = client.chat.completions.create(
12
- messages=[{"role": "user", "content": query}],
13
- model="llama-3.3-70b-versatile",
14
- )
15
- return chat_completion.choices[0].message.content
16
-
17
- # Streamlit app interface
18
- def main():
19
- st.title("Health Assistant Chatbot")
20
-
21
- # Provide health-related options for users
22
- st.write("Please ask a health-related question. The chatbot can answer questions about fever, flu, cough, malaria, and typhoid symptoms.")
23
-
24
- # Input from the user
25
- user_input = st.text_input("Ask a health-related question:")
26
-
27
- if user_input:
28
- # Check if the question is health-related
29
- health_keywords = ["fever", "flu", "cough", "malaria", "typhoid"]
30
- if any(keyword in user_input.lower() for keyword in health_keywords):
31
- response = get_chat_response(user_input)
32
- st.write("Chatbot Response:", response)
33
- else:
34
- st.write("Sorry, I do not have knowledge of this topic. Please ask only health-related questions.")
35
-
36
- if __name__ == "__main__":
37
- main()
 
 
 
 
 
 
1
  import os
2
  import streamlit as st
3
  from groq import Groq
4
+ from dotenv import load_dotenv
5
 
6
+ # Load environment variables from the .env file
7
+ load_dotenv()
8
+
9
+ # Fetch the API key from the environment variable
10
  api_key = os.getenv("GROQ_API_KEY")
11
+
12
+ # Ensure the API key is set
13
+ if not api_key:
14
+ st.error("API key not found. Please make sure the GROQ_API_KEY is set in your .env file.")
15
+ else:
16
+ client = Groq(api_key=api_key)
17
+
18
+ # Function to call the Groq API and get the chatbot response
19
+ def get_chat_response(query):
20
+ chat_completion = client.chat.completions.create(
21
+ messages=[{"role": "user", "content": query}],
22
+ model="llama-3.3-70b-versatile",
23
+ )
24
+ return chat_completion.choices[0].message.content
25
+
26
+ # Streamlit app interface
27
+ def main():
28
+ st.title("Health Assistant Chatbot")
29
+
30
+ # Provide health-related options for users
31
+ st.write("Please ask a health-related question. The chatbot can answer questions about fever, flu, cough, malaria, and typhoid symptoms.")
32
+
33
+ # Input from the user
34
+ user_input = st.text_input("Ask a health-related question:")
35
+
36
+ if user_input:
37
+ # Check if the question is health-related
38
+ health_keywords = ["fever", "flu", "cough", "malaria", "typhoid"]
39
+ if any(keyword in user_input.lower() for keyword in health_keywords):
40
+ response = get_chat_response(user_input)
41
+ st.write("Chatbot Response:", response)
42
+ else:
43
+ st.write("Sorry, I do not have knowledge of this topic. Please ask only health-related questions.")
44
+
45
+ if __name__ == "__main__":
46
+ main()