File size: 3,204 Bytes
8dc647e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# FLUX.1-dev + PuLID Handler

High-quality image generation with optional character consistency using FLUX.1-dev and PuLID.

## Features

- **FLUX.1-dev**: Higher quality than schnell (28 steps vs 4)
- **PuLID Integration**: Character consistency across images via face embeddings
- **Dual Mode**: Normal generation or ID-consistent generation
- **Memory Optimization**: FP8 quantization and CPU offload for smaller GPUs

## GPU Requirements

| GPU | Mode | Features |
|-----|------|----------|
| A100 80GB | Full GPU | Best quality, PuLID, batch processing |
| L40S 48GB | CPU Offload + FP8 | Good quality, PuLID, single inference |

## API Modes

### 1. Normal Generation

```json

{

  "inputs": "A professional portrait of a business person",

  "parameters": {

    "mode": "generate",

    "width": 1344,

    "height": 768,

    "num_inference_steps": 28,

    "guidance_scale": 3.5

  }

}

```

### 2. Register Character Face

```json

{

  "inputs": "",

  "parameters": {

    "mode": "register",

    "face_image": "data:image/png;base64,...",

    "character_name": "Hero_A"

  }

}

```

Response:
```json

{

  "success": true,

  "character_id": "uuid-xxx",

  "character_name": "Hero_A",

  "embedding_cached": true

}

```

### 3. Generate with Character Consistency

```json

{

  "inputs": "Hero_A sitting in a coffee shop, morning light",

  "parameters": {

    "mode": "generate_with_ids",

    "character_ids": ["uuid-xxx"],

    "id_weight": 0.8,

    "width": 1344,

    "height": 768

  }

}

```

### 4. Check Cache

```json

{

  "inputs": "",

  "parameters": {

    "mode": "check_cache",

    "character_ids": ["uuid-xxx", "uuid-yyy"]

  }

}

```

### 5. Clear Cache

```json

{

  "inputs": "",

  "parameters": {

    "mode": "clear_cache",

    "character_ids": ["uuid-xxx"]

  }

}

```

## Parameters

| Parameter | Default | Description |
|-----------|---------|-------------|
| `num_inference_steps` | 28 | More steps = higher quality (25-50) |
| `guidance_scale` | 3.5 | Prompt adherence (3.0-7.0) |
| `width` | 1344 | Image width |
| `height` | 768 | Image height |
| `id_weight` | 0.8 | PuLID identity strength (0.0-1.0) |
| `max_batch_size` | 4 | Max images per batch |

## Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `ENABLE_PULID` | true | Enable PuLID character consistency |
| `ENABLE_FP8` | auto | FP8 quantization (auto/true/false) |
| `NUM_INFERENCE_STEPS` | 28 | Default inference steps |

## Deployment

1. Create a new model repository on Hugging Face Hub
2. Upload `handler.py` and `requirements.txt`
3. Create a Dedicated Endpoint (A100 80GB recommended)
4. Set Task type to "Custom"

## Cost Comparison (vs schnell)

| Model | Steps | Time/Image | Quality |
|-------|-------|------------|---------|
| schnell | 4 | ~1.5s | Good |
| dev | 28 | ~8s | Excellent |
| dev + PuLID | 28 | ~10s | Excellent + Consistent |

## References

- [FLUX.1-dev](https://huggingface.co/black-forest-labs/FLUX.1-dev)
- [PuLID](https://github.com/ToTheBeginning/PuLID)
- [PuLID-FLUX v0.9.1](https://huggingface.co/guozinan/PuLID)