Fitness / model_api.py
Harry2406's picture
Update model_api.py
db90509 verified
from huggingface_hub import InferenceClient
import os
def query_model(prompt):
try:
HF_TOKEN = os.getenv("HF_TOKEN")
# Check if token exists
if HF_TOKEN is None:
return "HF_TOKEN is NOT SET. Please configure it in Hugging Face Space settings."
# Initialize model
client = InferenceClient(
model="Qwen/Qwen2.5-7B-Instruct",
token=HF_TOKEN
)
# Generate response
response = client.chat_completion(
messages=[
{
"role": "system",
"content": (
"You are a certified professional fitness trainer. "
"Always generate a complete, structured 5-day workout plan. "
"Divide clearly into Day 1 to Day 5. "
"Include exercise name, sets, reps, and rest period."
)
},
{
"role": "user",
"content": prompt
}
],
max_tokens=1200,
temperature=0.6
)
return response.choices[0].message.content
except Exception as e:
return f"ERROR OCCURRED: {repr(e)}"