Springboardmen commited on
Commit
f2e3ff5
·
verified ·
1 Parent(s): 82314df

Upload 2 files

Browse files
Files changed (2) hide show
  1. model_api.py +25 -0
  2. prompt_builder.py +50 -0
model_api.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import InferenceClient
2
+ import os
3
+
4
+ def query_model(prompt):
5
+ try:
6
+ HF_TOKEN = os.getenv("HF_TOKEN")
7
+
8
+ client = InferenceClient(
9
+ model="Qwen/Qwen2.5-7B-Instruct",
10
+ token=HF_TOKEN
11
+ )
12
+
13
+ response = client.chat_completion(
14
+ messages=[
15
+ {"role": "system", "content": "You are a certified professional fitness trainer."},
16
+ {"role": "user", "content": prompt}
17
+ ],
18
+ max_tokens=2000,
19
+ temperature=0.7
20
+ )
21
+
22
+ return response.choices[0].message.content
23
+
24
+ except Exception as e:
25
+ return f"Error: {str(e)}"
prompt_builder.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def calculate_bmi(weight, height):
2
+ height_m = height / 100
3
+ return weight / (height_m ** 2)
4
+
5
+
6
+ def bmi_category(bmi):
7
+ if bmi < 18.5:
8
+ return "Underweight"
9
+ elif bmi < 25:
10
+ return "Normal Weight"
11
+ elif bmi < 30:
12
+ return "Overweight"
13
+ else:
14
+ return "Obese"
15
+
16
+
17
+ def build_prompt(name, age, gender, height, weight, goal, fitness_level, equipment):
18
+
19
+ bmi = calculate_bmi(weight, height)
20
+ bmi_status = bmi_category(bmi)
21
+
22
+ equipment_list = ", ".join(equipment) if equipment else "No Equipment"
23
+
24
+ prompt = f"""
25
+ You are a certified professional fitness trainer.
26
+
27
+ Create a structured 5-day personalized workout plan.
28
+
29
+ User Profile:
30
+ - Name: {name}
31
+ - Age: {age}
32
+ - Gender: {gender}
33
+ - Height: {height} cm
34
+ - Weight: {weight} kg
35
+ - BMI: {bmi:.2f} ({bmi_status})
36
+ - Goal: {goal}
37
+ - Fitness Level: {fitness_level}
38
+ - Available Equipment: {equipment_list}
39
+
40
+ Instructions:
41
+ 1. Divide clearly into Day 1 to Day 5.
42
+ 2. Include exercise name.
43
+ 3. Include sets and reps.
44
+ 4. Include rest period.
45
+ 5. Adjust intensity based on BMI category.
46
+ 6. Avoid unsafe exercises for beginners.
47
+ 7. Keep the plan professional and easy to follow.
48
+ """
49
+
50
+ return prompt, bmi, bmi_status