Instructions to use easytt1178/example-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use easytt1178/example-model with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("easytt1178/example-model", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download src/agents/code_agent.py from easytt1178/example-model: direct link, hf CLI and curl.
- Browser
- Download file 988 Bytes
-
https://huggingface.co/easytt1178/example-model/resolve/main/src/agents/code_agent.py
- Command line
-
hf download hf://easytt1178/example-model/src/agents/code_agent.py
-
curl -L -o code_agent.py https://huggingface.co/easytt1178/example-model/resolve/main/src/agents/code_agent.py
988 Bytes
| from typing import Optional | |
| from huggingface_hub import InferenceClient | |
| import os | |
| DEFAULT_MODEL = os.environ.get("HF_CODE_MODEL", "HuggingFaceH4/zephyr-7b-beta") | |
| def generate_code(prompt: str, language: str = "python", max_new_tokens: int = 512) -> str: | |
| """Generate code or technical text via HF Inference API. | |
| Falls back to a simple template if API call fails. | |
| """ | |
| client = InferenceClient(token=os.environ.get("HF_TOKEN")) | |
| system_hint = f"You are an expert {language} code assistant. Output only code unless explanation is requested." | |
| full_prompt = f"{system_hint}\nTask: {prompt}\nLanguage: {language}" | |
| try: | |
| text = client.text_generation( | |
| model=DEFAULT_MODEL, | |
| prompt=full_prompt, | |
| max_new_tokens=max_new_tokens, | |
| temperature=0.2, | |
| ) | |
| return text.strip() | |
| except Exception as e: | |
| return f"# Fallback template due to API error: {e}\nprint('Hello from {language} generator')\n" |