Spaces:
Sleeping
Sleeping
Download model_api.py from Sreehitha-V/FitPlan_4: direct link, hf CLI and curl.
- Browser
- Download file 745 Bytes
-
https://huggingface.co/spaces/Sreehitha-V/FitPlan_4/resolve/main/model_api.py
- Command line
-
hf download hf://spaces/Sreehitha-V/FitPlan_4/model_api.py
-
curl -L -o model_api.py https://huggingface.co/spaces/Sreehitha-V/FitPlan_4/resolve/main/model_api.py
745 Bytes
| from huggingface_hub import InferenceClient | |
| import os | |
| def query_model(prompt): | |
| try: | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| client = InferenceClient( | |
| model="meta-llama/Meta-Llama-3-8B-Instruct", | |
| token=HF_TOKEN | |
| ) | |
| response = client.chat_completion( | |
| messages=[ | |
| {"role": "system", "content": "You are a certified professional fitness trainer."}, | |
| {"role": "user", "content": prompt} | |
| ], | |
| max_tokens=2400, # increase slightly | |
| temperature=0.6, # lower randomness | |
| top_p=0.9 | |
| ) | |
| return response.choices[0].message.content | |
| except Exception as e: | |
| return f"Error: {str(e)}" |