Download model_api.py from Shrey0405/FitAi: direct link, hf CLI and curl.
- Browser
- Download file 718 Bytes
-
https://huggingface.co/spaces/Shrey0405/FitAi/resolve/main/model_api.py
- Command line
-
hf download hf://spaces/Shrey0405/FitAi/model_api.py
-
curl -L -o model_api.py https://huggingface.co/spaces/Shrey0405/FitAi/resolve/main/model_api.py
718 Bytes
| from huggingface_hub import InferenceClient | |
| import os | |
| def query_model(prompt): | |
| try: | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| # You can also set provider at the client level | |
| client = InferenceClient(api_key=HF_TOKEN, provider="auto") | |
| response = client.chat.completions.create( | |
| model="Qwen/Qwen2.5-7B-Instruct", | |
| messages=[ | |
| {"role": "system", "content": "You are a professional fitness trainer."}, | |
| {"role": "user", "content": prompt} | |
| ], | |
| max_tokens=1500, | |
| temperature=0.7 | |
| ) | |
| return response.choices[0].message.content | |
| except Exception as e: | |
| return f"Error: {str(e)}" |