YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

Stable Diffusion 3.5 Custom Handler

This is a custom handler for deploying the stabilityai/stable-diffusion-3.5-large-turbo model on Hugging Face Inference Endpoints.

Files

  • handler.py: The main custom handler implementation
  • requirements.txt: Required dependencies
  • test_handler.py: Test script to verify the handler works
  • README.md: This file

Handler Features

The custom handler supports:

  • Text-to-image generation using Stable Diffusion 3.5 Large Turbo
  • Configurable parameters:
    • num_inference_steps: Number of inference steps (default: 1)
    • guidance_scale: Guidance scale (default: 0.0)
    • width: Image width (default: 1024)
    • height: Image height (default: 1024)
    • seed: Random seed for reproducible results

Deployment Steps

1. Create a Hugging Face Repository

  1. Go to Hugging Face and create a new repository
  2. Name it something like your-username/stable-diffusion-3.5-handler

2. Upload the Handler Files

Upload these files to your repository:

  • handler.py
  • requirements.txt

3. Deploy as Inference Endpoint

  1. Go to Hugging Face Inference Endpoints
  2. Click "New Endpoint"
  3. Select your repository
  4. Choose your cloud provider and region
  5. Select an appropriate instance type (GPU recommended)
  6. Set the task to "Custom"
  7. Deploy the endpoint

API Usage

Once deployed, you can call the endpoint with:

import requests

url = "https://your-endpoint-url"
headers = {"Authorization": "Bearer YOUR_TOKEN"}

payload = {
    "inputs": "A beautiful sunset over mountains, digital art",
    "num_inference_steps": 1,
    "guidance_scale": 0.0,
    "width": 1024,
    "height": 1024,
    "seed": 42
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

# The result contains a base64-encoded image
image_data = result["image"]

Response Format

The handler returns a JSON object with:

{
    "image": "base64_encoded_image_string",
    "prompt": "original_prompt",
    "parameters": {
        "num_inference_steps": 1,
        "guidance_scale": 0.0,
        "width": 1024,
        "height": 1024,
        "seed": 42
    }
}

Error Handling

If an error occurs, the response will contain:

{
    "error": "Error message describing what went wrong"
}

Testing Locally

To test the handler locally:

pip install -r requirements.txt
python test_handler.py

Notes

  • The handler uses torch.float16 for memory efficiency
  • GPU acceleration is automatically enabled if available
  • Memory efficient attention is enabled if xformers is available
  • The model is loaded once during initialization for optimal performance
Downloads last month
3
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support