| import streamlit as st |
| from groq import Groq |
| import os |
| dotenv_path = ".env" |
| from dotenv import load_dotenv |
|
|
| |
| load_dotenv(dotenv_path) |
| GROQ_API_KEY = os.getenv("GROQ_API_KEY") |
|
|
| |
| client = Groq(api_key=GROQ_API_KEY) |
|
|
| def get_fitness_response(user_input): |
| messages = [ |
| {"role": "system", "content": "You are a fitness assistant. You only answer fitness-related questions and provide relevant tips. If asked anything else, respond with: 'Sorry, I do not have knowledge of it. Please ask only fitness-related questions.'"}, |
| {"role": "user", "content": user_input} |
| ] |
| |
| completion = client.chat.completions.create( |
| model="deepseek-r1-distill-qwen-32b", |
| messages=messages, |
| temperature=0.6, |
| max_completion_tokens=4096, |
| top_p=0.95, |
| stream=True, |
| stop=None, |
| ) |
| |
| response = "" |
| for chunk in completion: |
| response += chunk.choices[0].delta.content or "" |
| |
| return response |
|
|
| |
| st.title("Fitness Assistant Chatbot") |
| st.write("Ask your fitness-related queries below.") |
|
|
| |
| user_input = st.text_input("Enter your query:") |
|
|
| if user_input: |
| response = get_fitness_response(user_input) |
| st.write(response) |
|
|
| |
| st.subheader("Select a fitness category:") |
| option = st.radio("Choose an option:", ["Weight Loss", "Diet", "Running ","gym", "protion control"]) |
|
|
| if option == "Weight Loss": |
| st.write("### Tips for Weight Loss:") |
| st.write("- Maintain a calorie deficit.") |
| st.write("- Exercise regularly (cardio and strength training).") |
| st.write("- Stay hydrated and get enough sleep.") |
| st.write("- Avoid processed foods and added sugars.") |
|
|
| elif option == "Diet": |
| st.write("### Diet Tips:") |
| st.write("- Eat a balanced diet with proteins, carbs, and healthy fats.") |
| st.write("- Include fiber-rich foods to improve digestion.") |
| st.write("- Avoid junk food and limit alcohol intake.") |
| st.write("- Plan meals and portion sizes to control calorie intake.") |
|
|
| elif option == "Running Symptoms": |
| st.write("### Common Running Issues and Solutions:") |
| st.write("- **Knee Pain**: Strengthen leg muscles and use proper running shoes.") |
| st.write("- **Shin Splints**: Avoid running on hard surfaces and stretch before running.") |
| st.write("- **Dehydration**: Drink enough water before and after running.") |
| st.write("- **Fatigue**: Ensure proper rest and nutrition to maintain energy levels.") |
|
|