Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,17 +43,17 @@ flux_generator = FluxGenerator()
|
|
| 43 |
@spaces.GPU
|
| 44 |
@torch.inference_mode()
|
| 45 |
def generate_image(
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
num_steps,
|
| 49 |
start_step,
|
| 50 |
guidance,
|
| 51 |
seed,
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
id_weight=1.0,
|
| 55 |
-
neg_prompt="",
|
| 56 |
-
true_cfg=1.0,
|
| 57 |
timestep_to_start_cfg=1,
|
| 58 |
max_sequence_length=128,
|
| 59 |
):
|
|
@@ -154,18 +154,16 @@ _HEADER_ = '''
|
|
| 154 |
<h1 style="font-size: 2.5rem; font-weight: 700; margin-bottom: 1rem; display: contents;">PuLID for FLUX</h1>
|
| 155 |
<p style="font-size: 1rem; margin-bottom: 1.5rem;">Paper: <a href='https://arxiv.org/abs/2404.16022' target='_blank'>PuLID: Pure and Lightning ID Customization via Contrastive Alignment</a> | Codes: <a href='https://github.com/ToTheBeginning/PuLID' target='_blank'>GitHub</a></p>
|
| 156 |
</div>
|
| 157 |
-
|
| 158 |
❗️❗️❗️**Tips:**
|
| 159 |
- `timestep to start inserting ID:` The smaller the value, the higher the fidelity, but the lower the editability; the higher the value, the lower the fidelity, but the higher the editability. **The recommended range for this value is between 0 and 4**. For photorealistic scenes, we recommend using 4; for stylized scenes, we recommend using 0-1. If you are not satisfied with the similarity, you can lower this value; conversely, if you are not satisfied with the editability, you can increase this value.
|
| 160 |
- `true CFG scale:` In most scenarios, it is recommended to use a fake CFG, i.e., setting the true CFG scale to 1, and just adjusting the guidance scale. This is also more efficiency. However, in a few cases, utilizing a true CFG can yield better results. For more detaileds, please refer to the [doc](https://github.com/ToTheBeginning/PuLID/blob/main/docs/pulid_for_flux.md#useful-tips).
|
| 161 |
-
- please refer to the <a href='https://github.com/ToTheBeginning/PuLID/blob/main/docs/pulid_for_flux.md' target='_blank'>github doc</a> for more details and info about the model, we provide the detail explanation about the above two parameters in the doc.
|
| 162 |
-
- we provide some examples in the bottom, you can try these example prompts first
|
| 163 |
''' # noqa E501
|
| 164 |
|
| 165 |
_CITE_ = r"""
|
| 166 |
If PuLID is helpful, please help to ⭐ the <a href='https://github.com/ToTheBeginning/PuLID' target='_blank'> Github Repo</a>. Thanks!
|
| 167 |
---
|
| 168 |
-
|
| 169 |
📧 **Contact**
|
| 170 |
If you have any questions or feedbacks, feel free to open a discussion or contact <b>[email protected]</b>.
|
| 171 |
""" # noqa E501
|
|
@@ -217,22 +215,22 @@ def create_demo(args, model_name: str, device: str = "cuda" if torch.cuda.is_ava
|
|
| 217 |
[
|
| 218 |
'portrait, side view',
|
| 219 |
'example_inputs/liuyifei.png',
|
| 220 |
-
4, 4,
|
| 221 |
],
|
| 222 |
[
|
| 223 |
'white-haired woman with vr technology atmosphere, revolutionary exceptional magnum with remarkable details', # noqa E501
|
| 224 |
'example_inputs/liuyifei.png',
|
| 225 |
-
4, 4,
|
| 226 |
],
|
| 227 |
[
|
| 228 |
'a young child is eating Icecream',
|
| 229 |
'example_inputs/liuyifei.png',
|
| 230 |
-
4, 4,
|
| 231 |
],
|
| 232 |
[
|
| 233 |
'a man is holding a sign with text \"PuLID for FLUX\", winter, snowing, top of the mountain',
|
| 234 |
'example_inputs/pengwei.jpg',
|
| 235 |
-
4, 4,
|
| 236 |
],
|
| 237 |
[
|
| 238 |
'portrait, candle light',
|
|
@@ -256,22 +254,24 @@ def create_demo(args, model_name: str, device: str = "cuda" if torch.cuda.is_ava
|
|
| 256 |
],
|
| 257 |
]
|
| 258 |
gr.Examples(examples=example_inps, inputs=[prompt, id_image, start_step, guidance, seed, true_cfg],
|
| 259 |
-
label='fake CFG'
|
|
|
|
| 260 |
|
| 261 |
example_inps = [
|
| 262 |
[
|
| 263 |
'portrait, made of ice sculpture',
|
| 264 |
'example_inputs/lecun.jpg',
|
| 265 |
-
1, 1,
|
| 266 |
],
|
| 267 |
]
|
| 268 |
gr.Examples(examples=example_inps, inputs=[prompt, id_image, start_step, guidance, seed, true_cfg],
|
| 269 |
-
label='true CFG'
|
|
|
|
| 270 |
|
| 271 |
generate_btn.click(
|
| 272 |
fn=generate_image,
|
| 273 |
-
inputs=[
|
| 274 |
-
|
| 275 |
outputs=[output_image, seed_output, intermediate_output],
|
| 276 |
)
|
| 277 |
|
|
@@ -296,4 +296,4 @@ if __name__ == "__main__":
|
|
| 296 |
huggingface_hub.login(os.getenv('HF_TOKEN'))
|
| 297 |
|
| 298 |
demo = create_demo(args, args.name, args.device, args.offload)
|
| 299 |
-
demo.launch()
|
|
|
|
| 43 |
@spaces.GPU
|
| 44 |
@torch.inference_mode()
|
| 45 |
def generate_image(
|
| 46 |
+
prompt,
|
| 47 |
+
id_image,
|
|
|
|
| 48 |
start_step,
|
| 49 |
guidance,
|
| 50 |
seed,
|
| 51 |
+
true_cfg,
|
| 52 |
+
width=896,
|
| 53 |
+
height=1152,
|
| 54 |
+
num_steps=20,
|
| 55 |
id_weight=1.0,
|
| 56 |
+
neg_prompt="bad quality, worst quality, text, signature, watermark, extra limbs",
|
|
|
|
| 57 |
timestep_to_start_cfg=1,
|
| 58 |
max_sequence_length=128,
|
| 59 |
):
|
|
|
|
| 154 |
<h1 style="font-size: 2.5rem; font-weight: 700; margin-bottom: 1rem; display: contents;">PuLID for FLUX</h1>
|
| 155 |
<p style="font-size: 1rem; margin-bottom: 1.5rem;">Paper: <a href='https://arxiv.org/abs/2404.16022' target='_blank'>PuLID: Pure and Lightning ID Customization via Contrastive Alignment</a> | Codes: <a href='https://github.com/ToTheBeginning/PuLID' target='_blank'>GitHub</a></p>
|
| 156 |
</div>
|
|
|
|
| 157 |
❗️❗️❗️**Tips:**
|
| 158 |
- `timestep to start inserting ID:` The smaller the value, the higher the fidelity, but the lower the editability; the higher the value, the lower the fidelity, but the higher the editability. **The recommended range for this value is between 0 and 4**. For photorealistic scenes, we recommend using 4; for stylized scenes, we recommend using 0-1. If you are not satisfied with the similarity, you can lower this value; conversely, if you are not satisfied with the editability, you can increase this value.
|
| 159 |
- `true CFG scale:` In most scenarios, it is recommended to use a fake CFG, i.e., setting the true CFG scale to 1, and just adjusting the guidance scale. This is also more efficiency. However, in a few cases, utilizing a true CFG can yield better results. For more detaileds, please refer to the [doc](https://github.com/ToTheBeginning/PuLID/blob/main/docs/pulid_for_flux.md#useful-tips).
|
| 160 |
+
- `Learn more about the model:` please refer to the <a href='https://github.com/ToTheBeginning/PuLID/blob/main/docs/pulid_for_flux.md' target='_blank'>github doc</a> for more details and info about the model, we provide the detail explanation about the above two parameters in the doc.
|
| 161 |
+
- `Examples:` we provide some examples in the bottom, you can try these example prompts first
|
| 162 |
''' # noqa E501
|
| 163 |
|
| 164 |
_CITE_ = r"""
|
| 165 |
If PuLID is helpful, please help to ⭐ the <a href='https://github.com/ToTheBeginning/PuLID' target='_blank'> Github Repo</a>. Thanks!
|
| 166 |
---
|
|
|
|
| 167 |
📧 **Contact**
|
| 168 |
If you have any questions or feedbacks, feel free to open a discussion or contact <b>[email protected]</b>.
|
| 169 |
""" # noqa E501
|
|
|
|
| 215 |
[
|
| 216 |
'portrait, side view',
|
| 217 |
'example_inputs/liuyifei.png',
|
| 218 |
+
4, 4, 180825677246321775, 1
|
| 219 |
],
|
| 220 |
[
|
| 221 |
'white-haired woman with vr technology atmosphere, revolutionary exceptional magnum with remarkable details', # noqa E501
|
| 222 |
'example_inputs/liuyifei.png',
|
| 223 |
+
4, 4, 16942328329935464989, 1
|
| 224 |
],
|
| 225 |
[
|
| 226 |
'a young child is eating Icecream',
|
| 227 |
'example_inputs/liuyifei.png',
|
| 228 |
+
4, 4, 4527590969012358757, 1
|
| 229 |
],
|
| 230 |
[
|
| 231 |
'a man is holding a sign with text \"PuLID for FLUX\", winter, snowing, top of the mountain',
|
| 232 |
'example_inputs/pengwei.jpg',
|
| 233 |
+
4, 4, 6273700647573240909, 1
|
| 234 |
],
|
| 235 |
[
|
| 236 |
'portrait, candle light',
|
|
|
|
| 254 |
],
|
| 255 |
]
|
| 256 |
gr.Examples(examples=example_inps, inputs=[prompt, id_image, start_step, guidance, seed, true_cfg],
|
| 257 |
+
label='fake CFG', cache_examples='lazy', outputs=[output_image, seed_output],
|
| 258 |
+
fn=generate_image)
|
| 259 |
|
| 260 |
example_inps = [
|
| 261 |
[
|
| 262 |
'portrait, made of ice sculpture',
|
| 263 |
'example_inputs/lecun.jpg',
|
| 264 |
+
1, 1, 7717391560531186077, 5
|
| 265 |
],
|
| 266 |
]
|
| 267 |
gr.Examples(examples=example_inps, inputs=[prompt, id_image, start_step, guidance, seed, true_cfg],
|
| 268 |
+
label='true CFG', cache_examples='lazy', outputs=[output_image, seed_output],
|
| 269 |
+
fn=generate_image)
|
| 270 |
|
| 271 |
generate_btn.click(
|
| 272 |
fn=generate_image,
|
| 273 |
+
inputs=[prompt, id_image, start_step, guidance, seed, true_cfg, width, height, num_steps, id_weight,
|
| 274 |
+
neg_prompt, timestep_to_start_cfg, max_sequence_length],
|
| 275 |
outputs=[output_image, seed_output, intermediate_output],
|
| 276 |
)
|
| 277 |
|
|
|
|
| 296 |
huggingface_hub.login(os.getenv('HF_TOKEN'))
|
| 297 |
|
| 298 |
demo = create_demo(args, args.name, args.device, args.offload)
|
| 299 |
+
demo.launch()
|