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/vision_agent.py from easytt1178/example-model: direct link, hf CLI and curl.
- Browser
- Download file 862 Bytes
-
https://huggingface.co/easytt1178/example-model/resolve/main/src/agents/vision_agent.py
- Command line
-
hf download hf://easytt1178/example-model/src/agents/vision_agent.py
-
curl -L -o vision_agent.py https://huggingface.co/easytt1178/example-model/resolve/main/src/agents/vision_agent.py
862 Bytes
| from typing import Optional | |
| from huggingface_hub import InferenceClient | |
| from PIL import Image | |
| import io | |
| import os | |
| TEXT_TO_IMAGE_MODEL = os.environ.get("HF_IMAGE_MODEL", "stabilityai/stable-diffusion-2-1") | |
| def generate_image(prompt: str, guidance_scale: float = 7.5, num_inference_steps: int = 30) -> Image.Image: | |
| """Generate an image from text using HF Inference API.""" | |
| client = InferenceClient(token=os.environ.get("HF_TOKEN")) | |
| try: | |
| img_bytes = client.text_to_image( | |
| model=TEXT_TO_IMAGE_MODEL, | |
| prompt=prompt, | |
| guidance_scale=guidance_scale, | |
| num_inference_steps=num_inference_steps, | |
| ) | |
| return Image.open(io.BytesIO(img_bytes)) | |
| except Exception as e: | |
| # Return a placeholder image | |
| img = Image.new("RGB", (512, 512), color=(240, 240, 240)) | |
| return img |