Views
No views yet
hf-inference-endpoint/
├── handler.py # Custom handler implementation
├── requirements.txt # Python dependencies
├── README.md # This file
└── CLAUDE.md # AI documentationhandler.py and requirements.txt to the repohandler.py and requirements.txt in the repo root1curl -X POST https://your-endpoint.endpoints.huggingface.cloud \
2 -H "Authorization: Bearer $HF_TOKEN" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "inputs": "A majestic lion wearing a crown, digital art, highly detailed",
6 "parameters": {
7 "negative_prompt": "blurry, low quality, distorted",
8 "num_inference_steps": 50,
9 "guidance_scale": 7.5,
10 "width": 1024,
11 "height": 1024,
12 "seed": 42,
13 "output_format": "jpeg"
14 }
15 }'1{
2 "image": "<base64-encoded-image>",
3 "content_type": "image/jpeg",
4 "parameters": {
5 "prompt": "A majestic lion...",
6 "negative_prompt": "blurry...",
7 "num_inference_steps": 50,
8 "guidance_scale": 7.5,
9 "width": 1024,
10 "height": 1024,
11 "seed": 42
12 }
13}| Parameter | Type | Default | Description |
|---|---|---|---|
inputs | string | required | The text prompt for image generation |
negative_prompt | string | "" | What to avoid in the image |
num_inference_steps | int | 50 | Number of denoising steps (20-100) |
guidance_scale | float | 7.5 | How closely to follow the prompt (1-20) |
width | int | 1024 | Image width (512-2048, multiple of 8) |
height | int | 1024 | Image height (512-2048, multiple of 8) |
seed | int | null | Random seed for reproducibility |
output_format | string | "jpeg" | Output format: "jpeg" or "png" |
use_refiner | bool | false | Use SDXL refiner for higher quality |
refiner_strength | float | 0.3 | Refiner denoising strength |
1import base64
2from PIL import Image
3import io
4
5response = requests.post(endpoint_url, json=payload, headers=headers)
6result = response.json()
7
8image_data = base64.b64decode(result["image"])
9image = Image.open(io.BytesIO(image_data))
10image.save("output.jpg")1const response = await fetch(endpointUrl, { method: 'POST', headers, body: JSON.stringify(payload) });
2const result = await response.json();
3
4const imageBuffer = Buffer.from(result.image, 'base64');
5fs.writeFileSync('output.jpg', imageBuffer);handler.py:1self.refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained(
2 "stabilityai/stable-diffusion-xl-refiner-1.0",
3 torch_dtype=self.dtype,
4 use_safetensors=True,
5 variant="fp16" if self.dtype == torch.float16 else None,
6)
7self.refiner.to(self.device)handler.py:model_id = "your-org/your-fine-tuned-sdxl"num_inference_stepsself.pipe.enable_attention_slicing()num_inference_steps to 25-30