Spaces:
Sleeping
Sleeping
Download model_api.py from srbhavya01/Module_2: direct link, hf CLI and curl.
- Browser
- Download file 731 Bytes
-
https://huggingface.co/spaces/srbhavya01/Module_2/resolve/main/model_api.py
- Command line
-
hf download hf://spaces/srbhavya01/Module_2/model_api.py
-
curl -L -o model_api.py https://huggingface.co/spaces/srbhavya01/Module_2/resolve/main/model_api.py
731 Bytes
| import streamlit as st | |
| from huggingface_hub import InferenceClient | |
| def query_model(prompt): | |
| try: | |
| # Read token from Streamlit secrets | |
| HF_TOKEN = st.secrets["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=800, | |
| temperature=0.7 | |
| ) | |
| return response.choices[0].message.content | |
| except Exception as e: | |
| return f"Error: {str(e)}" |