Azmathussainthebo's picture
Create app.py
de24fad verified
import os
import streamlit as st
from groq import Groq
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# Initialize the Groq API client using the API key from the environment variable
client = Groq(
api_key=os.environ.get("GROQ_API_KEY"),
)
# Function to handle fitness-related queries
def get_fitness_advice(query):
fitness_keywords = ['workout', 'gym', 'diet', 'exercise', 'muscle', 'health recovery', 'nutrition', 'strength', 'fat loss']
# Check if the query is health/fitness-related
if any(keyword in query.lower() for keyword in fitness_keywords):
# Send the query to the Groq API for a response
response = client.query(query)
return response.get('answer', 'Sorry, I could not find a solution for your query.')
else:
return "Sorry, I do not have knowledge of this topic. Please ask me only health and fitness-related questions."
# Streamlit UI
st.title("Health & Fitness Chatbot")
st.write("Welcome! Ask me anything about fitness, workout routines, diet, or health recovery.")
# User input for the query
user_input = st.text_input("What health or fitness question do you have?")
if user_input:
response = get_fitness_advice(user_input)
st.write("Response:", response)