File size: 1,819 Bytes
f3bb0df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf90edc
 
 
 
 
 
 
f3bb0df
bf90edc
f3bb0df
 
 
 
 
 
 
 
 
 
 
bf90edc
f3bb0df
 
 
 
bf90edc
f3bb0df
 
 
 
 
bf90edc
f3bb0df
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
48
49
50
51
52
import os
import streamlit as st
from groq import Groq
from dotenv import load_dotenv

# Load API key from .env file
load_dotenv()
api_key = os.getenv("GROQ_API_KEY")

# Check if API key is set
if not api_key:
    st.error("⚠️ Error: GROQ_API_KEY is missing. Please set it in the .env file.")
    st.stop()

# Initialize the Groq client
client = Groq(api_key=api_key)

# Function to get chatbot response
def get_fitness_response(user_question):
    # Define keywords related to fitness, weight loss, and health
    fitness_keywords = [
        "health", "fitness", "exercise", "diet", "nutrition", "weight loss", "workout", "calories", 
        "meal plan", "cardio", "strength training", "fat loss", "BMI", "hydration", "metabolism", 
        "protein intake", "muscle gain", "recovery", "supplements", "healthy habits", "intermittent fasting"
    ]
    
    if any(keyword in user_question.lower() for keyword in fitness_keywords):
        # Call Groq API to generate a response
        completion = client.chat.completions.create(
            model="deepseek-r1-distill-llama-70b",
            messages=[{"role": "user", "content": user_question}],
            temperature=0.6,
            max_completion_tokens=512,
            top_p=0.95,
            stream=False,
        )
        return completion.choices[0].message['content']
    else:
        return "⚠️ This chatbot only answers fitness, health, and weight loss-related questions."

# Streamlit UI
st.set_page_config(page_title="Health & Fitness Chatbot", layout="centered")
st.title("💪 Health & Fitness Chatbot")
st.write("Ask me anything about fitness, weight loss, workouts, and nutrition!")

# User Input
user_input = st.text_input("Type your question:")

if user_input:
    response = get_fitness_response(user_input)
    st.write(response)