Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +75 -0
- README.md +50 -7
- app.py +453 -0
- examples/011d56ec-477d-4fe8-b9f1-12d08c109bdf.webp +3 -0
- examples/01d3fe21-162f-4dc0-8bf6-dcc4165125bb.webp +3 -0
- examples/02d7daf5-a732-4c65-a10b-2778f159d193.webp +3 -0
- examples/05620500-6fb8-406b-9ea9-7b9e1afe699e.webp +3 -0
- examples/0f2d052b-6ccf-46e2-821d-d073ead679ac.webp +3 -0
- examples/0f5d38f9-d04a-498e-aaef-9dae01da8c6d.webp +3 -0
- examples/13233320-a579-489d-8946-7b3274775a8f.webp +3 -0
- examples/16708ba4-0aac-4247-9ccc-3d8c4b4e27d8.webp +3 -0
- examples/25ed3f18-2597-4530-ae92-6eb30b855225.webp +3 -0
- examples/27696b53-3f93-4f15-a7c0-0aecc425b543.webp +3 -0
- examples/2d02ee93-6278-4aa9-8fb9-3ca8d4c89dbb.webp +3 -0
- examples/2fac1fad-886d-4344-b6b2-97ed05cf1b35.webp +3 -0
- examples/386bf1a3-a74f-414e-956d-3532c2d7b1ec.webp +3 -0
- examples/3acf3276-0572-490e-b8ce-334833a6ca20.webp +3 -0
- examples/3e7b1d18-236a-45d7-b919-4bc4504b4a7c.webp +3 -0
- examples/3f4d7519-6c33-491f-bad8-661f1bf03601.webp +0 -0
- examples/447da49d-dcd0-46ec-9ca8-20127c0f07d1.webp +3 -0
- examples/469fc64a-e35d-484a-8362-f12fcb7212fa.webp +3 -0
- examples/49fd6d29-231a-4254-a507-304c1b6de119.webp +3 -0
- examples/4ab2fd4e-8d3f-4539-842b-87c6d45fbe18.webp +3 -0
- examples/4f703275-173e-405e-9a86-c86cc8fde01b.webp +3 -0
- examples/530f0874-145f-498d-aed4-b6f642137419.webp +3 -0
- examples/57f4af16-40dd-4022-89b4-5cd6e7b8e0b5.webp +3 -0
- examples/5a0bfab1-3527-410c-a98f-c44cc88ea750.webp +3 -0
- examples/6059360b-9b94-4821-9e68-3f05a1e91070.webp +3 -0
- examples/6a84c701-3388-498d-abf8-eea1cf1d1667.webp +3 -0
- examples/6ae02ff5-e65f-45c9-81e9-daca1931b62b.webp +3 -0
- examples/6c04c931-ef74-4d1b-bd26-61dcc9dc56f6.webp +3 -0
- examples/7794a497-5176-4a5e-9aa4-0366dc81e410.webp +3 -0
- examples/7922c916-518b-4c07-a7d1-819ecc4ae88c.webp +3 -0
- examples/7adabfc5-0028-4df3-94f9-e9490ccdeb76.webp +3 -0
- examples/849c51b8-87da-4572-9ec9-d0e514c22ba5.webp +3 -0
- examples/895cfefb-8b12-4d57-89ea-e396f1554440.webp +3 -0
- examples/8c08b1b8-ddfd-428e-86bc-7b07d789f7fa.webp +3 -0
- examples/8c265cf7-51ec-44fd-9436-30fbd96491de.webp +3 -0
- examples/8e26fdb3-8623-4418-b68d-089e760006fe.webp +3 -0
- examples/8ffd565d-7915-4353-b78d-cc11111c71da.webp +3 -0
- examples/90972d17-5686-4a88-a605-6b175137f655.webp +3 -0
- examples/93ada464-6ce0-420c-9f7d-0d6c810c741a.webp +3 -0
- examples/9664b431-48dc-4c5c-9873-3de0468cc717.webp +3 -0
- examples/9bd2638a-d848-4dbc-8a62-78039487bae4.webp +3 -0
- examples/9d4b89d1-ad3b-4527-acb4-c956e01ec078.webp +3 -0
- examples/README.md +15 -0
- examples/a5fa8e4a-9064-402e-b7d2-3d6254af97cb.webp +0 -0
- examples/a64d5702-f199-4667-baea-f0ab25bcf706.webp +3 -0
- examples/a65548fa-e7a8-4a8a-9471-6fb102de66b5.webp +3 -0
- examples/aa74e9d4-7ace-4b1f-9a68-a166976fb1fb.webp +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,78 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
examples/011d56ec-477d-4fe8-b9f1-12d08c109bdf.webp filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
examples/01d3fe21-162f-4dc0-8bf6-dcc4165125bb.webp filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
examples/02d7daf5-a732-4c65-a10b-2778f159d193.webp filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
examples/05620500-6fb8-406b-9ea9-7b9e1afe699e.webp filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
examples/0f2d052b-6ccf-46e2-821d-d073ead679ac.webp filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
examples/0f5d38f9-d04a-498e-aaef-9dae01da8c6d.webp filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
examples/13233320-a579-489d-8946-7b3274775a8f.webp filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
examples/16708ba4-0aac-4247-9ccc-3d8c4b4e27d8.webp filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
examples/25ed3f18-2597-4530-ae92-6eb30b855225.webp filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
examples/27696b53-3f93-4f15-a7c0-0aecc425b543.webp filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
examples/2d02ee93-6278-4aa9-8fb9-3ca8d4c89dbb.webp filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
examples/2fac1fad-886d-4344-b6b2-97ed05cf1b35.webp filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
examples/386bf1a3-a74f-414e-956d-3532c2d7b1ec.webp filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
examples/3acf3276-0572-490e-b8ce-334833a6ca20.webp filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
examples/3e7b1d18-236a-45d7-b919-4bc4504b4a7c.webp filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
examples/447da49d-dcd0-46ec-9ca8-20127c0f07d1.webp filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
examples/469fc64a-e35d-484a-8362-f12fcb7212fa.webp filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
examples/49fd6d29-231a-4254-a507-304c1b6de119.webp filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
examples/4ab2fd4e-8d3f-4539-842b-87c6d45fbe18.webp filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
examples/4f703275-173e-405e-9a86-c86cc8fde01b.webp filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
examples/530f0874-145f-498d-aed4-b6f642137419.webp filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
examples/57f4af16-40dd-4022-89b4-5cd6e7b8e0b5.webp filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
examples/5a0bfab1-3527-410c-a98f-c44cc88ea750.webp filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
examples/6059360b-9b94-4821-9e68-3f05a1e91070.webp filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
examples/6a84c701-3388-498d-abf8-eea1cf1d1667.webp filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
examples/6ae02ff5-e65f-45c9-81e9-daca1931b62b.webp filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
examples/6c04c931-ef74-4d1b-bd26-61dcc9dc56f6.webp filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
examples/7794a497-5176-4a5e-9aa4-0366dc81e410.webp filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
examples/7922c916-518b-4c07-a7d1-819ecc4ae88c.webp filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
examples/7adabfc5-0028-4df3-94f9-e9490ccdeb76.webp filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
examples/849c51b8-87da-4572-9ec9-d0e514c22ba5.webp filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
examples/895cfefb-8b12-4d57-89ea-e396f1554440.webp filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
examples/8c08b1b8-ddfd-428e-86bc-7b07d789f7fa.webp filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
examples/8c265cf7-51ec-44fd-9436-30fbd96491de.webp filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
examples/8e26fdb3-8623-4418-b68d-089e760006fe.webp filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
examples/8ffd565d-7915-4353-b78d-cc11111c71da.webp filter=lfs diff=lfs merge=lfs -text
|
| 72 |
+
examples/90972d17-5686-4a88-a605-6b175137f655.webp filter=lfs diff=lfs merge=lfs -text
|
| 73 |
+
examples/93ada464-6ce0-420c-9f7d-0d6c810c741a.webp filter=lfs diff=lfs merge=lfs -text
|
| 74 |
+
examples/9664b431-48dc-4c5c-9873-3de0468cc717.webp filter=lfs diff=lfs merge=lfs -text
|
| 75 |
+
examples/9bd2638a-d848-4dbc-8a62-78039487bae4.webp filter=lfs diff=lfs merge=lfs -text
|
| 76 |
+
examples/9d4b89d1-ad3b-4527-acb4-c956e01ec078.webp filter=lfs diff=lfs merge=lfs -text
|
| 77 |
+
examples/a64d5702-f199-4667-baea-f0ab25bcf706.webp filter=lfs diff=lfs merge=lfs -text
|
| 78 |
+
examples/a65548fa-e7a8-4a8a-9471-6fb102de66b5.webp filter=lfs diff=lfs merge=lfs -text
|
| 79 |
+
examples/aa74e9d4-7ace-4b1f-9a68-a166976fb1fb.webp filter=lfs diff=lfs merge=lfs -text
|
| 80 |
+
examples/adea5906-f3be-4283-9b31-b357a37800c9.webp filter=lfs diff=lfs merge=lfs -text
|
| 81 |
+
examples/bf8274b8-1db3-4d3e-b185-8a4ee7c98168.webp filter=lfs diff=lfs merge=lfs -text
|
| 82 |
+
examples/c6f9bab3-a041-4bcd-a9ef-5246a65b39d9.webp filter=lfs diff=lfs merge=lfs -text
|
| 83 |
+
examples/c74003dd-cde6-41ed-a66c-d8eb12767b67.webp filter=lfs diff=lfs merge=lfs -text
|
| 84 |
+
examples/d085337f-fdc8-419c-8f6f-fd21f32a612e.webp filter=lfs diff=lfs merge=lfs -text
|
| 85 |
+
examples/d194ae64-f876-4a67-9190-52391a1ada78.webp filter=lfs diff=lfs merge=lfs -text
|
| 86 |
+
examples/df248326-4cc6-4413-a2fe-06d0f3235842.webp filter=lfs diff=lfs merge=lfs -text
|
| 87 |
+
examples/e636800f-257b-4fa5-adb3-853b647f75b1.webp filter=lfs diff=lfs merge=lfs -text
|
| 88 |
+
examples/edf53ce0-2f5b-4f1e-9a36-3aca54237698.webp filter=lfs diff=lfs merge=lfs -text
|
| 89 |
+
examples/eed82398-ad69-4328-b5a3-0cd8952b25b7.webp filter=lfs diff=lfs merge=lfs -text
|
| 90 |
+
examples/ef7735f9-96ff-4da7-a2ba-64dd63fd0250.webp filter=lfs diff=lfs merge=lfs -text
|
| 91 |
+
examples/f263765e-e4d7-4683-87dd-b18fa77280a7.webp filter=lfs diff=lfs merge=lfs -text
|
| 92 |
+
examples/f53a2acb-be77-4799-b041-964c7906459c.webp filter=lfs diff=lfs merge=lfs -text
|
| 93 |
+
examples/f7b1d96d-8f47-40c2-b166-1eaf59bd20ba.webp filter=lfs diff=lfs merge=lfs -text
|
| 94 |
+
examples/f85dbf4f-8504-4b6a-b30d-4681738270a0.webp filter=lfs diff=lfs merge=lfs -text
|
| 95 |
+
examples/fa6cb3bf-2367-4f03-a9dd-a451e7afbe74.webp filter=lfs diff=lfs merge=lfs -text
|
| 96 |
+
examples/fe74ca55-e4ff-49a7-92b5-3b9abe89c72d.webp filter=lfs diff=lfs merge=lfs -text
|
| 97 |
+
examples/ff689e81-11c8-415e-852e-4e08ac0d0ea3.webp filter=lfs diff=lfs merge=lfs -text
|
| 98 |
+
examples/generated_en_1.webp filter=lfs diff=lfs merge=lfs -text
|
| 99 |
+
examples/generated_en_2.webp filter=lfs diff=lfs merge=lfs -text
|
| 100 |
+
examples/generated_en_3.webp filter=lfs diff=lfs merge=lfs -text
|
| 101 |
+
examples/generated_en_4.webp filter=lfs diff=lfs merge=lfs -text
|
| 102 |
+
examples/generated_running_shoes.webp filter=lfs diff=lfs merge=lfs -text
|
| 103 |
+
examples/generated_zh_1.webp filter=lfs diff=lfs merge=lfs -text
|
| 104 |
+
examples/generated_zh_2.webp filter=lfs diff=lfs merge=lfs -text
|
| 105 |
+
examples/generated_zh_3.webp filter=lfs diff=lfs merge=lfs -text
|
| 106 |
+
examples/generated_zh_4.webp filter=lfs diff=lfs merge=lfs -text
|
| 107 |
+
examples/generated_zh_5.webp filter=lfs diff=lfs merge=lfs -text
|
| 108 |
+
examples/generated_zh_6.webp filter=lfs diff=lfs merge=lfs -text
|
| 109 |
+
examples/generated_zh_7.webp filter=lfs diff=lfs merge=lfs -text
|
| 110 |
+
examples/transparent_anime_bride.png filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,13 +1,56 @@
|
|
| 1 |
---
|
| 2 |
-
title: Qwen
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.28.0
|
| 8 |
-
python_version: '3.12'
|
| 9 |
app_file: app.py
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Qwen-Image-2.1
|
| 3 |
+
emoji: 🖼️
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.28.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
+
short_description: Generate and edit images with Qwen-Image-2.1
|
| 10 |
+
python_version: "3.12"
|
| 11 |
+
startup_duration_timeout: 1h
|
| 12 |
+
license: other
|
| 13 |
+
license_name: qwen-research
|
| 14 |
+
license_link: https://huggingface.co/Qwen/Qwen-Image-2.1/blob/main/LICENSE
|
| 15 |
---
|
| 16 |
|
| 17 |
+
# Qwen-Image-2.1
|
| 18 |
+
|
| 19 |
+
Text-to-image generation and multi-image editing with
|
| 20 |
+
[`Qwen/Qwen-Image-2.1`](https://huggingface.co/Qwen/Qwen-Image-2.1), running on ZeroGPU
|
| 21 |
+
through the `QwenImage21Pipeline` in `diffusers`.
|
| 22 |
+
|
| 23 |
+
* **Text to image** — leave the input gallery empty and describe what you want.
|
| 24 |
+
* **Image editing** — upload up to 10 images and refer to them as `<image1>` … `<image10>`
|
| 25 |
+
in the prompt (upload order).
|
| 26 |
+
* **Transparency** — the model natively decodes RGBA. Ask for it in the prompt, e.g.
|
| 27 |
+
*"This is an RGBA image with transparency. … The image has alpha channel and the
|
| 28 |
+
background is transparent."*
|
| 29 |
+
|
| 30 |
+
## Prompt enhancement
|
| 31 |
+
|
| 32 |
+
The **Enhance prompt** checkbox calls a companion Space,
|
| 33 |
+
[`hugging-apps/qwen-image-2-1-prompt-enhancer`](https://huggingface.co/spaces/hugging-apps/qwen-image-2-1-prompt-enhancer),
|
| 34 |
+
which keeps both official rewriters (`Qwen-Image-2.1-PE-T2I` and `Qwen-Image-2.1-PE-I2I`)
|
| 35 |
+
warm and resident on their own GPU worker. Splitting them out keeps this Space's GPU
|
| 36 |
+
allocation dedicated to diffusion.
|
| 37 |
+
|
| 38 |
+
## Safety
|
| 39 |
+
|
| 40 |
+
Editing requests (any submission with input images) are screened with
|
| 41 |
+
[`hfmlsoc/ncii-guard-v02`](https://huggingface.co/hfmlsoc/ncii-guard-v02) before anything
|
| 42 |
+
is generated.
|
| 43 |
+
|
| 44 |
+
## Example assets
|
| 45 |
+
|
| 46 |
+
The images under `examples/` are the official demo assets from the
|
| 47 |
+
[`Qwen/Qwen-Image-2.1`](https://huggingface.co/spaces/Qwen/Qwen-Image-2.1) Space,
|
| 48 |
+
redistributed here under the Qwen Research License for non-commercial demonstration.
|
| 49 |
+
|
| 50 |
+
## License
|
| 51 |
+
|
| 52 |
+
> Qwen is licensed under the Qwen RESEARCH LICENSE AGREEMENT, Copyright (c) 2026
|
| 53 |
+
> Hangzhou Tongyi Laboratory Technology Co., Ltd. All Rights Reserved.
|
| 54 |
+
|
| 55 |
+
Research / evaluation use only — see the
|
| 56 |
+
[license](https://huggingface.co/Qwen/Qwen-Image-2.1/blob/main/LICENSE).
|
app.py
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Qwen-Image-2.1 — unified text-to-image generation and image editing on ZeroGPU.
|
| 2 |
+
|
| 3 |
+
Pipeline for one request:
|
| 4 |
+
|
| 5 |
+
1. NCII guard (CPU, main process) — image-input requests have their prompt screened
|
| 6 |
+
with ``hfmlsoc/ncii-guard-v02`` before any GPU time is reserved.
|
| 7 |
+
2. Optional prompt enhancement — delegated over the Gradio API to a companion Space
|
| 8 |
+
that keeps ``Qwen-Image-2.1-PE-T2I`` and ``Qwen-Image-2.1-PE-I2I`` warm.
|
| 9 |
+
3. Generation — ``QwenImage21Pipeline`` inside ``@spaces.GPU``.
|
| 10 |
+
|
| 11 |
+
Steps 1 and 2 deliberately run outside the GPU fork so a rejected or enhanced prompt
|
| 12 |
+
costs the visitor no ZeroGPU quota.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import os
|
| 16 |
+
|
| 17 |
+
os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
|
| 18 |
+
|
| 19 |
+
import spaces # noqa: E402 — must precede torch / any CUDA-touching import
|
| 20 |
+
|
| 21 |
+
import json # noqa: E402
|
| 22 |
+
import math # noqa: E402
|
| 23 |
+
import random # noqa: E402
|
| 24 |
+
import tempfile # noqa: E402
|
| 25 |
+
import time # noqa: E402
|
| 26 |
+
|
| 27 |
+
import gradio as gr # noqa: E402
|
| 28 |
+
import torch # noqa: E402
|
| 29 |
+
from diffusers import QwenImage21Pipeline # noqa: E402
|
| 30 |
+
from PIL import Image # noqa: E402
|
| 31 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer # noqa: E402
|
| 32 |
+
|
| 33 |
+
MODEL_ID = "Qwen/Qwen-Image-2.1"
|
| 34 |
+
GUARD_ID = "hfmlsoc/ncii-guard-v02"
|
| 35 |
+
PE_SPACE_ID = os.environ.get("PE_SPACE_ID", "hugging-apps/qwen-image-2-1-prompt-enhancer")
|
| 36 |
+
|
| 37 |
+
MAX_SEED = 2**31 - 1
|
| 38 |
+
MAX_INPUT_IMAGES = 10
|
| 39 |
+
EXAMPLE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "examples")
|
| 40 |
+
|
| 41 |
+
# Shown verbatim when the guard rejects a prompt — deliberately non-explicit.
|
| 42 |
+
GUARD_REJECTION_MESSAGE = "prompt invalid based on our classifiers, try again"
|
| 43 |
+
# See the model card's threshold sweep: 0.5 is the balanced precision/recall point.
|
| 44 |
+
GUARD_THRESHOLD = 0.5
|
| 45 |
+
|
| 46 |
+
# The aspect ratios the model card lists, at its 2048-base resolution.
|
| 47 |
+
BASE_RESOLUTION = 2048
|
| 48 |
+
ASPECT_RATIOS = {
|
| 49 |
+
"1:1": (2048, 2048),
|
| 50 |
+
"4:3": (2400, 1792),
|
| 51 |
+
"3:4": (1792, 2400),
|
| 52 |
+
"3:2": (2528, 1696),
|
| 53 |
+
"2:3": (1696, 2528),
|
| 54 |
+
"16:9": (2752, 1536),
|
| 55 |
+
"9:16": (1536, 2752),
|
| 56 |
+
}
|
| 57 |
+
RESOLUTION_CHOICES = [("1K — fastest", 1024), ("1.5K", 1536), ("2K — model default", 2048)]
|
| 58 |
+
|
| 59 |
+
TRANSPARENCY_INFO = (
|
| 60 |
+
"Describe what to generate, or how to edit the input images (refer to them as "
|
| 61 |
+
"<image1>…<image10> in upload order). For a transparent RGBA result, phrase the prompt as: "
|
| 62 |
+
"“This is an RGBA image with transparency. … The image has alpha channel and the "
|
| 63 |
+
"background is transparent.”"
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# --------------------------------------------------------------------------------------
|
| 67 |
+
# Models
|
| 68 |
+
# --------------------------------------------------------------------------------------
|
| 69 |
+
|
| 70 |
+
print(f"[load] {MODEL_ID} …", flush=True)
|
| 71 |
+
pipe = QwenImage21Pipeline.from_pretrained(MODEL_ID, torch_dtype=torch.bfloat16)
|
| 72 |
+
pipe = pipe.to("cuda")
|
| 73 |
+
print("[load] pipeline ready", flush=True)
|
| 74 |
+
|
| 75 |
+
# The guard is a 270M classifier and stays on the CPU in the main process, so a prompt can
|
| 76 |
+
# be rejected before any GPU allocation is requested. Its tokenizer carries the homoglyph /
|
| 77 |
+
# zero-width normalizer, so it must come from this repo.
|
| 78 |
+
print(f"[load] {GUARD_ID} …", flush=True)
|
| 79 |
+
guard_tokenizer = AutoTokenizer.from_pretrained(GUARD_ID)
|
| 80 |
+
guard_model = AutoModelForSequenceClassification.from_pretrained(
|
| 81 |
+
GUARD_ID, dtype=torch.float32
|
| 82 |
+
).eval()
|
| 83 |
+
print("[load] guard ready", flush=True)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def guard_score(text: str) -> float:
|
| 87 |
+
"""Probability that ``text`` is a request for non-consensual intimate imagery."""
|
| 88 |
+
batch = guard_tokenizer(
|
| 89 |
+
text or "", truncation=True, max_length=256, padding=True, return_tensors="pt"
|
| 90 |
+
)
|
| 91 |
+
with torch.no_grad():
|
| 92 |
+
logits = guard_model(**batch).logits.float()
|
| 93 |
+
return torch.softmax(logits, dim=-1)[0, 1].item()
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
# --------------------------------------------------------------------------------------
|
| 97 |
+
# Prompt enhancement (delegated to the companion Space)
|
| 98 |
+
# --------------------------------------------------------------------------------------
|
| 99 |
+
|
| 100 |
+
_pe_client = None
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def get_pe_client():
|
| 104 |
+
"""Lazily connect to the prompt-enhancement Space (its models are already warm)."""
|
| 105 |
+
global _pe_client
|
| 106 |
+
if _pe_client is None:
|
| 107 |
+
from gradio_client import Client
|
| 108 |
+
|
| 109 |
+
token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
| 110 |
+
_pe_client = Client(
|
| 111 |
+
PE_SPACE_ID, hf_token=token, httpx_kwargs={"timeout": 900}, verbose=False
|
| 112 |
+
)
|
| 113 |
+
return _pe_client
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def enhance_prompt(prompt: str, image_paths: list[str]) -> tuple[str, str]:
|
| 117 |
+
"""Rewrite ``prompt`` with the official PE models. Returns (prompt, wh_ratio)."""
|
| 118 |
+
from gradio_client import handle_file
|
| 119 |
+
|
| 120 |
+
client = get_pe_client()
|
| 121 |
+
started = time.perf_counter()
|
| 122 |
+
result = client.predict(
|
| 123 |
+
prompt=prompt,
|
| 124 |
+
image_paths=[handle_file(p) for p in image_paths],
|
| 125 |
+
max_new_tokens=1536,
|
| 126 |
+
enable_thinking=True,
|
| 127 |
+
seed=0,
|
| 128 |
+
randomize_seed=True,
|
| 129 |
+
api_name="/enhance",
|
| 130 |
+
)
|
| 131 |
+
rewritten, wh_ratio = str(result[0]).strip(), str(result[1]).strip()
|
| 132 |
+
print(f"[enhance] {time.perf_counter() - started:.1f}s -> ratio={wh_ratio!r}", flush=True)
|
| 133 |
+
return (rewritten or prompt), wh_ratio
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
# --------------------------------------------------------------------------------------
|
| 137 |
+
# Helpers
|
| 138 |
+
# --------------------------------------------------------------------------------------
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def normalize_gallery(gallery) -> list[str]:
|
| 142 |
+
"""Reduce a ``gr.Gallery`` value to a flat list of local file paths."""
|
| 143 |
+
paths: list[str] = []
|
| 144 |
+
for item in gallery or []:
|
| 145 |
+
if isinstance(item, (tuple, list)):
|
| 146 |
+
item = item[0]
|
| 147 |
+
if isinstance(item, dict):
|
| 148 |
+
item = item.get("path") or item.get("image") or item.get("name")
|
| 149 |
+
if isinstance(item, dict):
|
| 150 |
+
item = item.get("path")
|
| 151 |
+
if isinstance(item, Image.Image):
|
| 152 |
+
tmp = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
|
| 153 |
+
item.save(tmp.name)
|
| 154 |
+
item = tmp.name
|
| 155 |
+
if isinstance(item, str) and item:
|
| 156 |
+
paths.append(item)
|
| 157 |
+
return paths
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def resolve_size(resolution: int, aspect_ratio: str) -> tuple[int | None, int | None]:
|
| 161 |
+
"""Map a resolution tier + aspect ratio onto the model card's width/height pairs."""
|
| 162 |
+
if not aspect_ratio or aspect_ratio == "Auto" or aspect_ratio not in ASPECT_RATIOS:
|
| 163 |
+
return None, None
|
| 164 |
+
base_w, base_h = ASPECT_RATIOS[aspect_ratio]
|
| 165 |
+
scale = int(resolution) / BASE_RESOLUTION
|
| 166 |
+
round32 = lambda v: max(32, int(round(v * scale / 32)) * 32) # noqa: E731
|
| 167 |
+
return round32(base_w), round32(base_h)
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def estimate_duration(
|
| 171 |
+
input_images=None,
|
| 172 |
+
prompt="",
|
| 173 |
+
negative_prompt="",
|
| 174 |
+
true_cfg_scale=1.0,
|
| 175 |
+
num_inference_steps=40,
|
| 176 |
+
seed=0,
|
| 177 |
+
resolution=1024,
|
| 178 |
+
aspect_ratio="Auto",
|
| 179 |
+
*args,
|
| 180 |
+
**kwargs,
|
| 181 |
+
):
|
| 182 |
+
"""Budget GPU seconds. Cost is ~linear in steps and ~quadratic in side length."""
|
| 183 |
+
try:
|
| 184 |
+
steps = int(num_inference_steps)
|
| 185 |
+
res = int(resolution)
|
| 186 |
+
cfg = float(true_cfg_scale)
|
| 187 |
+
except (TypeError, ValueError):
|
| 188 |
+
steps, res, cfg = 40, 1024, 1.0
|
| 189 |
+
n_images = len(input_images or [])
|
| 190 |
+
tokens = (res / 16.0) ** 2
|
| 191 |
+
per_step = 9.0e-5 * tokens * (2.0 if cfg > 1.0 else 1.0)
|
| 192 |
+
overhead = 18.0 + 4.0 * n_images + 6.0e-6 * res * res
|
| 193 |
+
return int(min(360, math.ceil(overhead + steps * per_step)))
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
# --------------------------------------------------------------------------------------
|
| 197 |
+
# Inference
|
| 198 |
+
# --------------------------------------------------------------------------------------
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
@spaces.GPU(duration=estimate_duration)
|
| 202 |
+
def generate_image(
|
| 203 |
+
input_images=None,
|
| 204 |
+
prompt: str = "",
|
| 205 |
+
negative_prompt: str = "",
|
| 206 |
+
true_cfg_scale: float = 1.0,
|
| 207 |
+
num_inference_steps: int = 40,
|
| 208 |
+
seed: int = 0,
|
| 209 |
+
resolution: int = 1024,
|
| 210 |
+
aspect_ratio: str = "Auto",
|
| 211 |
+
progress=gr.Progress(track_tqdm=True),
|
| 212 |
+
):
|
| 213 |
+
"""Generate or edit an image with Qwen-Image-2.1.
|
| 214 |
+
|
| 215 |
+
With no input images this is text-to-image; with one to ten input images it is
|
| 216 |
+
image editing, and the prompt may refer to them as <image1>…<image10>.
|
| 217 |
+
|
| 218 |
+
Args:
|
| 219 |
+
input_images: Up to 10 condition images. Leave empty for text-to-image.
|
| 220 |
+
prompt: What to generate, or how to edit the inputs.
|
| 221 |
+
negative_prompt: What to avoid. Only applied when true_cfg_scale > 1.
|
| 222 |
+
true_cfg_scale: Classifier-free guidance scale; 1.0 disables it.
|
| 223 |
+
num_inference_steps: Number of flow-matching steps.
|
| 224 |
+
seed: Random seed.
|
| 225 |
+
resolution: Target side length in pixels (1024, 1536 or 2048).
|
| 226 |
+
aspect_ratio: One of the model's supported ratios, or "Auto".
|
| 227 |
+
|
| 228 |
+
Returns:
|
| 229 |
+
The generated image, as RGBA (the model natively supports transparency).
|
| 230 |
+
"""
|
| 231 |
+
prompt = (prompt or "").strip()
|
| 232 |
+
if not prompt:
|
| 233 |
+
raise gr.Error("Please enter a prompt.")
|
| 234 |
+
|
| 235 |
+
image_paths = normalize_gallery(input_images)
|
| 236 |
+
if len(image_paths) > MAX_INPUT_IMAGES:
|
| 237 |
+
raise gr.Error(f"Up to {MAX_INPUT_IMAGES} input images are supported.")
|
| 238 |
+
|
| 239 |
+
condition_images = [Image.open(p) for p in image_paths] or None
|
| 240 |
+
width, height = resolve_size(resolution, aspect_ratio)
|
| 241 |
+
|
| 242 |
+
negative_prompt = (negative_prompt or "").strip()
|
| 243 |
+
call_kwargs = {}
|
| 244 |
+
if negative_prompt and float(true_cfg_scale) > 1.0:
|
| 245 |
+
call_kwargs["negative_prompt"] = negative_prompt
|
| 246 |
+
call_kwargs["true_cfg_scale"] = float(true_cfg_scale)
|
| 247 |
+
|
| 248 |
+
started = time.perf_counter()
|
| 249 |
+
image = pipe(
|
| 250 |
+
prompt=prompt,
|
| 251 |
+
image=condition_images,
|
| 252 |
+
height=height,
|
| 253 |
+
width=width,
|
| 254 |
+
output_resolution=int(resolution),
|
| 255 |
+
num_inference_steps=int(num_inference_steps),
|
| 256 |
+
generator=torch.Generator(device="cuda").manual_seed(int(seed) % (MAX_SEED + 1)),
|
| 257 |
+
**call_kwargs,
|
| 258 |
+
).images[0]
|
| 259 |
+
print(
|
| 260 |
+
f"[generate] images={len(image_paths)} steps={num_inference_steps} "
|
| 261 |
+
f"res={resolution} ratio={aspect_ratio} size={image.size} "
|
| 262 |
+
f"elapsed={time.perf_counter() - started:.1f}s",
|
| 263 |
+
flush=True,
|
| 264 |
+
)
|
| 265 |
+
return image
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def prepare(prompt, input_images, enhance, seed, randomize_seed, aspect_ratio):
|
| 269 |
+
"""Screen the prompt, optionally rewrite it, and resolve the seed — all off-GPU."""
|
| 270 |
+
prompt = (prompt or "").strip()
|
| 271 |
+
if not prompt:
|
| 272 |
+
raise gr.Error("Please enter a prompt.")
|
| 273 |
+
|
| 274 |
+
image_paths = normalize_gallery(input_images)
|
| 275 |
+
if len(image_paths) > MAX_INPUT_IMAGES:
|
| 276 |
+
raise gr.Error(f"Up to {MAX_INPUT_IMAGES} input images are supported.")
|
| 277 |
+
|
| 278 |
+
# Guard image-input requests before any GPU time is reserved.
|
| 279 |
+
if image_paths:
|
| 280 |
+
score = guard_score(prompt)
|
| 281 |
+
print(f"[guard] score={score:.3f} threshold={GUARD_THRESHOLD}", flush=True)
|
| 282 |
+
if score >= GUARD_THRESHOLD:
|
| 283 |
+
raise gr.Error(GUARD_REJECTION_MESSAGE)
|
| 284 |
+
|
| 285 |
+
resolved_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
|
| 286 |
+
|
| 287 |
+
final_prompt, rewritten_display = prompt, ""
|
| 288 |
+
if enhance:
|
| 289 |
+
try:
|
| 290 |
+
final_prompt, wh_ratio = enhance_prompt(prompt, image_paths)
|
| 291 |
+
rewritten_display = final_prompt
|
| 292 |
+
# Honour the rewriter's ratio only when the user left the choice open and
|
| 293 |
+
# there is no input image whose aspect ratio the pipeline should follow.
|
| 294 |
+
if wh_ratio and aspect_ratio == "Auto" and not image_paths:
|
| 295 |
+
if wh_ratio in ASPECT_RATIOS:
|
| 296 |
+
aspect_ratio = wh_ratio
|
| 297 |
+
except Exception as exc: # noqa: BLE001 — never let PE take the whole request down
|
| 298 |
+
print(f"[enhance] failed: {exc!r}", flush=True)
|
| 299 |
+
gr.Warning(f"Prompt enhancement unavailable, using the original prompt ({exc}).")
|
| 300 |
+
|
| 301 |
+
return final_prompt, rewritten_display, resolved_seed, aspect_ratio
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
# --------------------------------------------------------------------------------------
|
| 305 |
+
# Examples (Qwen's own demo cases, bundled under examples/)
|
| 306 |
+
# --------------------------------------------------------------------------------------
|
| 307 |
+
|
| 308 |
+
with open(os.path.join(EXAMPLE_DIR, "cases.json"), encoding="utf-8") as fh:
|
| 309 |
+
DEMO_CASES = json.load(fh)
|
| 310 |
+
|
| 311 |
+
T2I_EXAMPLES = [[c["prompt"]] for c in DEMO_CASES if not c["inputs"]]
|
| 312 |
+
T2I_LABELS = [c["title_en"] for c in DEMO_CASES if not c["inputs"]]
|
| 313 |
+
EDIT_EXAMPLES = [
|
| 314 |
+
[[os.path.join(EXAMPLE_DIR, name) for name in c["inputs"]], c["prompt"]]
|
| 315 |
+
for c in DEMO_CASES
|
| 316 |
+
if c["inputs"]
|
| 317 |
+
]
|
| 318 |
+
EDIT_LABELS = [c["title_en"] for c in DEMO_CASES if c["inputs"]]
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
# --------------------------------------------------------------------------------------
|
| 322 |
+
# UI
|
| 323 |
+
# --------------------------------------------------------------------------------------
|
| 324 |
+
|
| 325 |
+
css = """
|
| 326 |
+
#col-container { margin: 0 auto; max-width: 1100px; }
|
| 327 |
+
"""
|
| 328 |
+
|
| 329 |
+
with gr.Blocks(theme=gr.themes.Citrus(), css=css, title="Qwen-Image-2.1") as demo:
|
| 330 |
+
with gr.Column(elem_id="col-container"):
|
| 331 |
+
gr.HTML(
|
| 332 |
+
'<img src="https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Image/image2.1/logo.png"'
|
| 333 |
+
' alt="Qwen-Image logo" width="380" style="display:block;margin:0 auto;">'
|
| 334 |
+
)
|
| 335 |
+
|
| 336 |
+
with gr.Row():
|
| 337 |
+
with gr.Column():
|
| 338 |
+
input_images = gr.Gallery(
|
| 339 |
+
label="Input images (editing, up to 10)",
|
| 340 |
+
type="filepath",
|
| 341 |
+
interactive=True,
|
| 342 |
+
columns=5,
|
| 343 |
+
height=300,
|
| 344 |
+
show_label=True,
|
| 345 |
+
)
|
| 346 |
+
with gr.Column():
|
| 347 |
+
result = gr.Image(
|
| 348 |
+
label="Result",
|
| 349 |
+
type="pil",
|
| 350 |
+
image_mode="RGBA",
|
| 351 |
+
format="png",
|
| 352 |
+
height=300,
|
| 353 |
+
show_label=True,
|
| 354 |
+
)
|
| 355 |
+
|
| 356 |
+
prompt = gr.Textbox(
|
| 357 |
+
label="Prompt",
|
| 358 |
+
info=TRANSPARENCY_INFO,
|
| 359 |
+
lines=5,
|
| 360 |
+
max_lines=24,
|
| 361 |
+
placeholder="Describe what you want to generate or edit…",
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
with gr.Row():
|
| 365 |
+
enhance = gr.Checkbox(label="Enhance prompt", value=True, scale=1)
|
| 366 |
+
generate_button = gr.Button("Generate image", variant="primary", scale=2)
|
| 367 |
+
|
| 368 |
+
rewritten_prompt_output = gr.Textbox(
|
| 369 |
+
label="Rewritten prompt",
|
| 370 |
+
lines=4,
|
| 371 |
+
max_lines=20,
|
| 372 |
+
interactive=False,
|
| 373 |
+
show_copy_button=True,
|
| 374 |
+
placeholder="With prompt enhancement on, the rewritten prompt appears here.",
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
with gr.Accordion("Advanced settings", open=False):
|
| 378 |
+
with gr.Row():
|
| 379 |
+
resolution = gr.Dropdown(
|
| 380 |
+
label="Resolution", choices=RESOLUTION_CHOICES, value=1024
|
| 381 |
+
)
|
| 382 |
+
aspect_ratio = gr.Dropdown(
|
| 383 |
+
label="Aspect ratio",
|
| 384 |
+
choices=["Auto"] + list(ASPECT_RATIOS),
|
| 385 |
+
value="Auto",
|
| 386 |
+
info="Auto follows the input image, or squares up for text-to-image.",
|
| 387 |
+
)
|
| 388 |
+
num_inference_steps = gr.Slider(
|
| 389 |
+
label="Inference steps", minimum=8, maximum=60, step=1, value=40
|
| 390 |
+
)
|
| 391 |
+
with gr.Row():
|
| 392 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
|
| 393 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 394 |
+
negative_prompt = gr.Textbox(
|
| 395 |
+
label="Negative prompt",
|
| 396 |
+
value="",
|
| 397 |
+
lines=2,
|
| 398 |
+
info="Only applied when guidance is above 1.0.",
|
| 399 |
+
)
|
| 400 |
+
true_cfg_scale = gr.Slider(
|
| 401 |
+
label="True CFG scale", minimum=1.0, maximum=10.0, step=0.1, value=1.0
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
final_prompt_state = gr.State("")
|
| 405 |
+
|
| 406 |
+
gr.Markdown("### Examples")
|
| 407 |
+
gr.Markdown("**Text to image**")
|
| 408 |
+
gr.Examples(
|
| 409 |
+
examples=T2I_EXAMPLES,
|
| 410 |
+
example_labels=T2I_LABELS,
|
| 411 |
+
inputs=[prompt],
|
| 412 |
+
fn=generate_image,
|
| 413 |
+
outputs=[result],
|
| 414 |
+
cache_examples=True,
|
| 415 |
+
cache_mode="lazy",
|
| 416 |
+
label="Text-to-image cases",
|
| 417 |
+
)
|
| 418 |
+
gr.Markdown("**Image editing** — the example loads its reference images too")
|
| 419 |
+
gr.Examples(
|
| 420 |
+
examples=EDIT_EXAMPLES,
|
| 421 |
+
example_labels=EDIT_LABELS,
|
| 422 |
+
inputs=[input_images, prompt],
|
| 423 |
+
fn=generate_image,
|
| 424 |
+
outputs=[result],
|
| 425 |
+
cache_examples=True,
|
| 426 |
+
cache_mode="lazy",
|
| 427 |
+
label="Image-editing cases",
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
generate_button.click(
|
| 431 |
+
fn=prepare,
|
| 432 |
+
inputs=[prompt, input_images, enhance, seed, randomize_seed, aspect_ratio],
|
| 433 |
+
outputs=[final_prompt_state, rewritten_prompt_output, seed, aspect_ratio],
|
| 434 |
+
).then(
|
| 435 |
+
fn=generate_image,
|
| 436 |
+
inputs=[
|
| 437 |
+
input_images,
|
| 438 |
+
final_prompt_state,
|
| 439 |
+
negative_prompt,
|
| 440 |
+
true_cfg_scale,
|
| 441 |
+
num_inference_steps,
|
| 442 |
+
seed,
|
| 443 |
+
resolution,
|
| 444 |
+
aspect_ratio,
|
| 445 |
+
],
|
| 446 |
+
outputs=[result],
|
| 447 |
+
api_name="generate",
|
| 448 |
+
)
|
| 449 |
+
|
| 450 |
+
demo.queue(default_concurrency_limit=1, max_size=20)
|
| 451 |
+
|
| 452 |
+
if __name__ == "__main__":
|
| 453 |
+
demo.launch(mcp_server=True, allowed_paths=[EXAMPLE_DIR])
|
examples/011d56ec-477d-4fe8-b9f1-12d08c109bdf.webp
ADDED
|
Git LFS Details
|
examples/01d3fe21-162f-4dc0-8bf6-dcc4165125bb.webp
ADDED
|
Git LFS Details
|
examples/02d7daf5-a732-4c65-a10b-2778f159d193.webp
ADDED
|
Git LFS Details
|
examples/05620500-6fb8-406b-9ea9-7b9e1afe699e.webp
ADDED
|
Git LFS Details
|
examples/0f2d052b-6ccf-46e2-821d-d073ead679ac.webp
ADDED
|
Git LFS Details
|
examples/0f5d38f9-d04a-498e-aaef-9dae01da8c6d.webp
ADDED
|
Git LFS Details
|
examples/13233320-a579-489d-8946-7b3274775a8f.webp
ADDED
|
Git LFS Details
|
examples/16708ba4-0aac-4247-9ccc-3d8c4b4e27d8.webp
ADDED
|
Git LFS Details
|
examples/25ed3f18-2597-4530-ae92-6eb30b855225.webp
ADDED
|
Git LFS Details
|
examples/27696b53-3f93-4f15-a7c0-0aecc425b543.webp
ADDED
|
Git LFS Details
|
examples/2d02ee93-6278-4aa9-8fb9-3ca8d4c89dbb.webp
ADDED
|
Git LFS Details
|
examples/2fac1fad-886d-4344-b6b2-97ed05cf1b35.webp
ADDED
|
Git LFS Details
|
examples/386bf1a3-a74f-414e-956d-3532c2d7b1ec.webp
ADDED
|
Git LFS Details
|
examples/3acf3276-0572-490e-b8ce-334833a6ca20.webp
ADDED
|
Git LFS Details
|
examples/3e7b1d18-236a-45d7-b919-4bc4504b4a7c.webp
ADDED
|
Git LFS Details
|
examples/3f4d7519-6c33-491f-bad8-661f1bf03601.webp
ADDED
|
examples/447da49d-dcd0-46ec-9ca8-20127c0f07d1.webp
ADDED
|
Git LFS Details
|
examples/469fc64a-e35d-484a-8362-f12fcb7212fa.webp
ADDED
|
Git LFS Details
|
examples/49fd6d29-231a-4254-a507-304c1b6de119.webp
ADDED
|
Git LFS Details
|
examples/4ab2fd4e-8d3f-4539-842b-87c6d45fbe18.webp
ADDED
|
Git LFS Details
|
examples/4f703275-173e-405e-9a86-c86cc8fde01b.webp
ADDED
|
Git LFS Details
|
examples/530f0874-145f-498d-aed4-b6f642137419.webp
ADDED
|
Git LFS Details
|
examples/57f4af16-40dd-4022-89b4-5cd6e7b8e0b5.webp
ADDED
|
Git LFS Details
|
examples/5a0bfab1-3527-410c-a98f-c44cc88ea750.webp
ADDED
|
Git LFS Details
|
examples/6059360b-9b94-4821-9e68-3f05a1e91070.webp
ADDED
|
Git LFS Details
|
examples/6a84c701-3388-498d-abf8-eea1cf1d1667.webp
ADDED
|
Git LFS Details
|
examples/6ae02ff5-e65f-45c9-81e9-daca1931b62b.webp
ADDED
|
Git LFS Details
|
examples/6c04c931-ef74-4d1b-bd26-61dcc9dc56f6.webp
ADDED
|
Git LFS Details
|
examples/7794a497-5176-4a5e-9aa4-0366dc81e410.webp
ADDED
|
Git LFS Details
|
examples/7922c916-518b-4c07-a7d1-819ecc4ae88c.webp
ADDED
|
Git LFS Details
|
examples/7adabfc5-0028-4df3-94f9-e9490ccdeb76.webp
ADDED
|
Git LFS Details
|
examples/849c51b8-87da-4572-9ec9-d0e514c22ba5.webp
ADDED
|
Git LFS Details
|
examples/895cfefb-8b12-4d57-89ea-e396f1554440.webp
ADDED
|
Git LFS Details
|
examples/8c08b1b8-ddfd-428e-86bc-7b07d789f7fa.webp
ADDED
|
Git LFS Details
|
examples/8c265cf7-51ec-44fd-9436-30fbd96491de.webp
ADDED
|
Git LFS Details
|
examples/8e26fdb3-8623-4418-b68d-089e760006fe.webp
ADDED
|
Git LFS Details
|
examples/8ffd565d-7915-4353-b78d-cc11111c71da.webp
ADDED
|
Git LFS Details
|
examples/90972d17-5686-4a88-a605-6b175137f655.webp
ADDED
|
Git LFS Details
|
examples/93ada464-6ce0-420c-9f7d-0d6c810c741a.webp
ADDED
|
Git LFS Details
|
examples/9664b431-48dc-4c5c-9873-3de0468cc717.webp
ADDED
|
Git LFS Details
|
examples/9bd2638a-d848-4dbc-8a62-78039487bae4.webp
ADDED
|
Git LFS Details
|
examples/9d4b89d1-ad3b-4527-acb4-c956e01ec078.webp
ADDED
|
Git LFS Details
|
examples/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Demo cases
|
| 2 |
+
|
| 3 |
+
`cases.json` contains the 25 examples imported from `2.1 Demo Case.md`: 21 image-editing cases and 4 text-to-image cases. Input images retain their order from the document, including the 10-image room-furnishing example.
|
| 4 |
+
|
| 5 |
+
Images are bundled locally as lossless WebP files. Decoded RGB/RGBA pixels were verified against the downloaded originals. Reference outputs are displayed separately from generated results; the running-shoe reference was generated separately because the source document did not supply one.
|
| 6 |
+
|
| 7 |
+
Where the document supplies both `raw_prompt` and `positive_prompt`, the example uses the complete `positive_prompt`. Original fields remain in `source_prompts`. Markdown code fences, table escapes, and encoded line breaks are removed from the displayed prompt. These curated prompts load with prompt enhancement disabled so they are sent unchanged.
|
| 8 |
+
|
| 9 |
+
Titles have Chinese and English variants. Switching the interface language preserves the original language and content of each prompt.
|
| 10 |
+
|
| 11 |
+
## Generated reference outputs
|
| 12 |
+
|
| 13 |
+
The running-shoe case and all 11 original Chinese/English text-to-image examples now include outputs generated with `pre-qwen-image-2.1-eval-preprocess-0917`, seed 42. Their prompt enhancement settings match the corresponding example buttons. `generated_references.json` records the 11 text-to-image prompts, output filenames and generation settings; the running-shoe metadata is in `cases.json`. Generated outputs are stored as lossless WebP. No API keys or temporary download URLs are stored here.
|
| 14 |
+
|
| 15 |
+
The transparent anime bride example uses the supplied Chinese prompt verbatim with enhancement disabled. Its reference is an original RGBA PNG with verified transparent and semi-transparent pixels; generation metadata includes the request ID.
|
examples/a5fa8e4a-9064-402e-b7d2-3d6254af97cb.webp
ADDED
|
examples/a64d5702-f199-4667-baea-f0ab25bcf706.webp
ADDED
|
Git LFS Details
|
examples/a65548fa-e7a8-4a8a-9471-6fb102de66b5.webp
ADDED
|
Git LFS Details
|
examples/aa74e9d4-7ace-4b1f-9a68-a166976fb1fb.webp
ADDED
|
Git LFS Details
|