File size: 5,668 Bytes
f179fb3
 
2da2ac4
f179fb3
 
 
 
fe30f16
f179fb3
fe30f16
f179fb3
fe30f16
f179fb3
a781ddc
f179fb3
fe30f16
f179fb3
 
 
 
 
 
a781ddc
2da2ac4
 
 
 
a781ddc
 
2da2ac4
 
a781ddc
 
 
 
f179fb3
69e6233
f179fb3
2da2ac4
a781ddc
2da2ac4
f179fb3
 
69e6233
f179fb3
69e6233
 
 
 
 
f179fb3
 
fe30f16
f179fb3
 
 
 
 
 
 
 
 
 
 
 
 
fe30f16
f179fb3
 
 
 
 
 
 
 
fe30f16
f179fb3
 
 
 
 
 
 
 
fe30f16
f179fb3
 
 
 
 
 
 
 
fe30f16
f179fb3
 
 
 
 
 
 
 
fe30f16
f179fb3
 
 
 
 
 
 
 
fe30f16
f179fb3
 
 
 
 
 
 
 
fe30f16
f179fb3
 
 
a781ddc
f179fb3
 
fe30f16
f179fb3
 
 
 
 
 
fe30f16
f179fb3
 
 
 
 
 
fe30f16
f179fb3
 
 
 
 
 
fe30f16
f179fb3
 
 
 
 
 
 
 
 
 
fe30f16
f179fb3
 
 
 
 
fe30f16
f179fb3
a781ddc
 
 
 
f179fb3
 
 
 
fe30f16
f179fb3
a781ddc
 
f179fb3
 
fe30f16
f179fb3
 
a781ddc
f179fb3
 
fe30f16
f179fb3
 
 
 
 
 
 
fe30f16
f179fb3
fe30f16
a781ddc
f179fb3
 
a781ddc
fe30f16
 
 
a781ddc
954ca3f
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"""
Configuration file for Pixagram AI Pixel Art Generator
UPDATED VERSION with InstantID configuration
"""
import os
import torch

# Device configuration
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.float16 if device == "cuda" else torch.float32

# Model configuration
MODEL_REPO = "primerz/pixagram"
HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN", None)

# Model files
MODEL_FILES = {
    "checkpoint": "horizon.safetensors",
    "lora": "retroart.safetensors",
    "vae": "pixelate.safetensors"
}

# InstantID Configuration
INSTANTID_CONFIG = {
    "repo": "InstantX/InstantID",
    "controlnet_subfolder": "ControlNetModel",
    "ip_adapter_file": "ip-adapter.bin",
    "default_ip_scale": 0.8,
    "face_model_repo": "DIAMONIK7777/antelopev2"
}

# LORA configuration
TRIGGER_WORD = "p1x3l4rt, pixel art"

# Face detection configuration
FACE_DETECTION_CONFIG = {
    "model_name": "antelopev2",
    "det_size": (640, 640),
    "ctx_id": 0,
    "download_repo": "DIAMONIK7777/antelopev2",
    "root": "./models/insightface"
}

# Recommended resolutions
RECOMMENDED_SIZES = [
    (896, 1152),   # Portrait
    (1152, 896),   # Landscape
    (832, 1216),   # Tall portrait
    (1216, 832),   # Wide landscape
    (1024, 1024)   # Square
]

# Default generation parameters
DEFAULT_PARAMS = {
    "num_inference_steps": 12,
    "guidance_scale": 1.3,
    "strength": 0.50,
    "depth_control_scale": 0.75,
    "identity_control_scale": 0.85,
    "lora_scale": 1.0,
    "identity_preservation": 1.2,
    "enable_color_matching": False,
    "consistency_mode": True,
    "seed": -1
}

# Optimized preset configurations
PRESETS = {
    "Ultra Fidelity": {
        "strength": 0.40,
        "guidance_scale": 1.15,
        "identity_preservation": 1.8,
        "lora_scale": 0.8,
        "depth_control_scale": 0.65,
        "identity_control_scale": 0.95,
        "description": "Maximum face preservation - 96-98% similarity (Level 3)"
    },
    "Premium Portrait": {
        "strength": 0.52,
        "guidance_scale": 1.3,
        "identity_preservation": 1.35,
        "lora_scale": 1.1,
        "depth_control_scale": 0.75,
        "identity_control_scale": 0.85,
        "description": "Optimized balanced - strong pixel art + excellent face (92-94% similarity)"
    },
    "Balanced Portrait": {
        "strength": 0.50,
        "guidance_scale": 1.3,
        "identity_preservation": 1.2,
        "lora_scale": 1.0,
        "depth_control_scale": 0.75,
        "identity_control_scale": 0.85,
        "description": "Good balance between fidelity and style - 90-93% similarity"
    },
    "Artistic Excellence": {
        "strength": 0.58,
        "guidance_scale": 1.4,
        "identity_preservation": 1.2,
        "lora_scale": 1.2,
        "depth_control_scale": 0.78,
        "identity_control_scale": 0.75,
        "description": "Creative with strong likeness - 88-91% similarity"
    },
    "Style Focus": {
        "strength": 0.68,
        "guidance_scale": 1.5,
        "identity_preservation": 0.9,
        "lora_scale": 1.4,
        "depth_control_scale": 0.82,
        "identity_control_scale": 0.65,
        "description": "Maximum pixel art style - 83-87% similarity"
    },
    "Subtle Enhancement": {
        "strength": 0.38,
        "guidance_scale": 1.1,
        "identity_preservation": 1.9,
        "lora_scale": 0.75,
        "depth_control_scale": 0.60,
        "identity_control_scale": 0.98,
        "description": "Minimal transformation, photo-realistic - 97-99% similarity"
    }
}

# Multi-scale face processing (kept for reference but not used with InstantID pipeline)
MULTI_SCALE_FACTORS = [0.75, 1.0, 1.25]

# Adaptive parameter adjustment thresholds
ADAPTIVE_THRESHOLDS = {
    "small_face_size": 50000,
    "low_confidence": 0.8,
    "profile_angle": 20
}

# Adaptive parameter sets
ADAPTIVE_PARAMS = {
    "small_face": {
        "identity_preservation": 1.8,
        "identity_control_scale": 0.95,
        "guidance_scale": 1.2,
        "lora_scale": 0.8,
        "reason": "Small face detected - boosting preservation"
    },
    "low_confidence": {
        "identity_preservation": 1.6,
        "identity_control_scale": 0.9,
        "guidance_scale": 1.3,
        "lora_scale": 0.85,
        "reason": "Low confidence - increasing identity weight"
    },
    "profile_view": {
        "identity_preservation": 1.7,
        "identity_control_scale": 0.95,
        "guidance_scale": 1.2,
        "lora_scale": 0.85,
        "reason": "Profile view - enhancing preservation"
    }
}

# Caption generation settings
CAPTION_CONFIG = {
    "max_length": 20,
    "num_beams": 4
}

# Color matching settings
COLOR_MATCH_CONFIG = {
    "lab_lightness_blend": 0.15,
    "lab_color_blend_preserved": 0.05,
    "lab_color_blend_full": 0.20,
    "saturation_boost": 1.05,
    "gaussian_blur_kernel": (51, 51),
    "gaussian_blur_sigma": 20
}

# Face mask settings
FACE_MASK_CONFIG = {
    "padding": 0.1,
    "feather": 30
}

# Model download retry settings
DOWNLOAD_CONFIG = {
    "max_retries": 3,
    "retry_delay": 2
}

# Age brackets for demographic detection
AGE_BRACKETS = [
    (0, 18, "young"),
    (18, 30, "young adult"),
    (30, 50, "middle-aged"),
    (50, 150, "mature")
]

# CLIP skip setting
CLIP_SKIP = 2

# Identity boost multiplier (not used with InstantID pipeline - handled internally)
IDENTITY_BOOST_MULTIPLIER = 1.15

print(f"[CONFIG] Loaded configuration")
print(f"  Device: {device}")
print(f"  Dtype: {dtype}")
print(f"  Model Repo: {MODEL_REPO}")
print(f"  HuggingFace Token: {'Set' if HUGGINGFACE_TOKEN else 'Not set (using IP-based access)'}")
print(f"  InstantID: Enabled")