Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,81 +2,6 @@ import streamlit as st
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# ---------- MODEL QUERY FUNCTION ----------
|
| 6 |
-
def query_model(prompt):
|
| 7 |
-
try:
|
| 8 |
-
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
-
|
| 10 |
-
client = InferenceClient(
|
| 11 |
-
model="mistralai/Mistral-7B-Instruct-v0.2",
|
| 12 |
-
token=HF_TOKEN
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
response = client.chat_completion(
|
| 16 |
-
messages=[
|
| 17 |
-
{"role": "system", "content": "You are a certified professional fitness trainer."},
|
| 18 |
-
{"role": "user", "content": prompt}
|
| 19 |
-
],
|
| 20 |
-
max_tokens=2000,
|
| 21 |
-
temperature=0.7
|
| 22 |
-
)
|
| 23 |
-
|
| 24 |
-
return response.choices[0].message.content
|
| 25 |
-
|
| 26 |
-
except Exception as e:
|
| 27 |
-
return f"Error: {str(e)}"
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
# ---------- BMI FUNCTIONS ----------
|
| 31 |
-
def calculate_bmi(weight, height):
|
| 32 |
-
height_m = height / 100
|
| 33 |
-
return weight / (height_m ** 2)
|
| 34 |
-
|
| 35 |
-
def bmi_category(bmi):
|
| 36 |
-
if bmi < 18.5:
|
| 37 |
-
return "Underweight"
|
| 38 |
-
elif bmi < 25:
|
| 39 |
-
return "Normal Weight"
|
| 40 |
-
elif bmi < 30:
|
| 41 |
-
return "Overweight"
|
| 42 |
-
else:
|
| 43 |
-
return "Obese"
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
# ---------- PROMPT BUILDER ----------
|
| 47 |
-
def build_prompt(name, gender, height, weight, goal, fitness_level, equipment):
|
| 48 |
-
|
| 49 |
-
bmi = calculate_bmi(weight, height)
|
| 50 |
-
bmi_status = bmi_category(bmi)
|
| 51 |
-
|
| 52 |
-
equipment_list = ", ".join(equipment) if equipment else "No Equipment"
|
| 53 |
-
|
| 54 |
-
prompt = f"""
|
| 55 |
-
You are a certified professional fitness trainer.
|
| 56 |
-
Create a structured 5-day personalized workout plan.
|
| 57 |
-
|
| 58 |
-
User Profile:
|
| 59 |
-
- Name: {name}
|
| 60 |
-
- Gender: {gender}
|
| 61 |
-
- Height: {height} cm
|
| 62 |
-
- Weight: {weight} kg
|
| 63 |
-
- BMI: {bmi:.2f} ({bmi_status})
|
| 64 |
-
- Goal: {goal}
|
| 65 |
-
- Fitness Level: {fitness_level}
|
| 66 |
-
- Available Equipment: {equipment_list}
|
| 67 |
-
|
| 68 |
-
Instructions:
|
| 69 |
-
1. Divide clearly into Day 1 to Day 5.
|
| 70 |
-
2. Include exercise name.
|
| 71 |
-
3. Include sets and reps.
|
| 72 |
-
4. Include rest period.
|
| 73 |
-
5. Adjust intensity based on BMI category.
|
| 74 |
-
6. Avoid unsafe exercises for beginners.
|
| 75 |
-
7. Keep the plan professional and easy to follow.
|
| 76 |
-
"""
|
| 77 |
-
return prompt, bmi, bmi_status
|
| 78 |
-
|
| 79 |
-
|
| 80 |
# ---------- STREAMLIT UI ----------
|
| 81 |
st.title("🏋️ AI Personalized 5-Day Workout Planner")
|
| 82 |
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# ---------- STREAMLIT UI ----------
|
| 6 |
st.title("🏋️ AI Personalized 5-Day Workout Planner")
|
| 7 |
|