Spaces:
Sleeping
Sleeping
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() | |