Views
No views yet
User Details block to generate a coherent response.1[INST] You are a fitness assistant.
2
3User Details:
4Sex: {Sex}
5Age: {Age}
6Height: {Height} cm
7Weight: {Weight} kg
8Fitness Goal: {Goal}
9
10Generate a personalized fitness plan with clear headings:
11- Equipment Required
12- Exercise Plan
13- Diet Plan
14- Additional Recommendations [/INST]1import requests
2
3API_URL = "[https://api-inference.huggingface.co/models/KrishnaHuYaar/Fitness-Mistral-7B-Instruct-v0.1](https://api-inference.huggingface.co/models/KrishnaHuYaar/Fitness-Mistral-7B-Instruct-v0.1)"
4headers = {"Authorization": "Bearer YOUR_HF_TOKEN"}
5
6payload = {
7 "inputs": """[INST] You are a fitness assistant.
8User Details:
9Sex: Female
10Age: 30
11Height: 165 cm
12Weight: 60 kg
13Fitness Goal: Weight Loss
14
15Generate a personalized fitness plan with clear headings:
16- Equipment Required
17- Exercise Plan
18- Diet Plan
19- Additional Recommendations [/INST]"""
20}
21
22response = requests.post(API_URL, headers=headers, json=payload)
23print(response.json())pip install torch transformers accelerate1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4# Load the model
5model_name = "KrishnaHuYaar/Fitness-Mistral-7B-Instruct-v0.1"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype=torch.float16,
10 device_map="auto"
11)
12
13# Define the generation function
14def generate_plan(sex, age, height, weight, goal):
15 prompt = f"""[INST] You are a fitness assistant.
16
17User Details:
18Sex: {sex}
19Age: {age}
20Height: {height} cm
21Weight: {weight} kg
22Fitness Goal: {goal}
23
24Generate a personalized fitness plan with clear headings:
25- Equipment Required
26- Exercise Plan
27- Diet Plan
28- Additional Recommendations [/INST]"""
29
30 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
31
32 with torch.no_grad():
33 outputs = model.generate(
34 **inputs,
35 max_new_tokens=500,
36 do_sample=True,
37 temperature=0.7
38 )
39
40 return tokenizer.decode(outputs[0], skip_special_tokens=True).split("[/INST]")[-1]
41
42# Example Usage
43print(generate_plan("Male", 25, 175, 70, "Muscle Gain"))