File size: 1,670 Bytes
abeb042
 
 
a71309a
abeb042
a71309a
 
 
 
abeb042
a71309a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import streamlit as st
from groq import Groq
from dotenv import load_dotenv

# Load environment variables from the .env file
load_dotenv()

# Fetch the API key from the environment variable
api_key = os.getenv("GROQ_API_KEY")

# Ensure the API key is set
if not api_key:
    st.error("API key not found. Please make sure the GROQ_API_KEY is set in your .env file.")
else:
    client = Groq(api_key=api_key)

    # Function to call the Groq API and get the chatbot response
    def get_chat_response(query):
        chat_completion = client.chat.completions.create(
            messages=[{"role": "user", "content": query}],
            model="llama-3.3-70b-versatile",
        )
        return chat_completion.choices[0].message.content

    # Streamlit app interface
    def main():
        st.title("Health Assistant Chatbot")

        # Provide health-related options for users
        st.write("Please ask a health-related question. The chatbot can answer questions about fever, flu, cough, malaria, and typhoid symptoms.")

        # Input from the user
        user_input = st.text_input("Ask a health-related question:")

        if user_input:
            # Check if the question is health-related
            health_keywords = ["fever", "flu", "cough", "malaria", "typhoid"]
            if any(keyword in user_input.lower() for keyword in health_keywords):
                response = get_chat_response(user_input)
                st.write("Chatbot Response:", response)
            else:
                st.write("Sorry, I do not have knowledge of this topic. Please ask only health-related questions.")

    if __name__ == "__main__":
        main()