A Gradio-based demonstration for the Tongyi-MAI/Z-Image-Turbo diffusion pipeline, enhanced with a curated collection of LoRAs (Low-Rank Adaptations) for style transfer and creative image generation. Users can select from 27 pre-loaded LoRAs (e.g., Turbo Pencil, Ghibli Style, Pixel Art) or add custom ones from Hugging Face repositories. Generates high-quality images from text prompts, with trigger words automatically integrated for optimal results. Supports optimizations like AoTI compilation and FA3 for faster inference.
- LoRA Gallery: Interactive selection from 27 specialized LoRAs, each with preview images, trigger words, and direct links to Hugging Face repos.
- Custom LoRA Support: Input any Hugging Face repo (e.g., "Shakker-Labs/AWPortrait-Z") to dynamically load and use new styles; auto-detects weights, trigger words, and previews.
- Prompt Integration: Automatically prepends or appends LoRA trigger words to prompts for seamless style application.
- Advanced Controls: Adjustable steps (1-50), seed randomization, LoRA scale (0-3), resolution (up to 1536x1536), and CFG scale (forced to 0.0 for Turbo mode).
- Optimizations: Applies AoTI compilation and FA3 for reduced memory and faster generation on CUDA.
- Custom Theme: OrangeRedTheme with gradients, enhanced typography, and responsive CSS for a polished UI.
- Queueing and Progress: Handles up to 60 concurrent jobs with tqdm-tracked progress bars.
- Base Model Fallback: Generates without LoRAs using the pure Z-Image-Turbo pipeline.
- Python 3.10 or higher.
- CUDA-compatible GPU (recommended for bfloat16; falls back to CPU but slower).
- pip >= 23.0.0 (see pre-requirements.txt).
- Stable internet for initial model/LoRA downloads from Hugging Face.
-
Clone the repository:
git clone https://github.com/PRITHIVSAKTHIUR/Z-Image-Turbo-LoRA-DLC.git cd Z-Image-Turbo-LoRA-DLC -
Install pre-requirements (for pip version): Create a
pre-requirements.txtfile with the following content, then run:pip install -r pre-requirements.txtpre-requirements.txt content:
pip>=23.0.0 -
Install dependencies: Create a
requirements.txtfile with the following content, then run:pip install -r requirements.txtrequirements.txt content:
git+https://github.com/huggingface/diffusers.git@refs/pull/12790/head huggingface_hub gradio==6.1.0 sentencepiece transformers torchvision accelerate kernels spaces torch numpy peft -
Start the application:
python app.pyThe demo launches at
http://localhost:7860(or the provided URL if using Spaces).
-
Select LoRA: Browse the gallery and click a preview (e.g., "Turbo Pencil") to load it; the prompt placeholder updates with the style name.
-
Enter Prompt: Type a description (e.g., "a serene mountain landscape"); trigger words (e.g., "pencil sketch") are auto-added if applicable.
-
Configure Settings:
- Expand "Advanced Settings" for steps (default 9), seed, resolution, and LoRA scale (default 0.95).
- For custom LoRAs, enter a repo path (e.g., "Shakker-Labs/AWPortrait-Z") and press Enter.
-
Generate: Click "Generate" or submit the prompt; monitor the progress bar.
-
Output: View the generated image; download or regenerate with new seeds.
- Select "Ghibli Style" LoRA.
- Prompt: "a whimsical forest adventure".
- Settings: 1024x1024, 9 steps, seed 42.
- Output: Ghibli-inspired image with trigger "Ghibli Style" integrated.
| Index | Title | Trigger Word | Repo Example |
|---|---|---|---|
| 0 | Turbo Pencil | pencil sketch | Ttio2/Z-Image-Turbo-pencil-sketch |
| 1 | AWPortrait Z | Portrait | Shakker-Labs/AWPortrait-Z |
| 2 | Childrens Drawings | Children Drawings | ostris/z_image_turbo_childrens_drawings |
| ... | ... | ... | ... |
(Full list in code; supports 27 styles like Pixel Art, 80s Horror, etc.)
- LoRA Loading Errors: Ensure repo has
.safetensors; check console for warnings. Custom repos must match Z-Image-Turbo base. - Optimization Fails: AoTI/FA3 requires compatible hardware; fallback to standard pipeline without errors.
- OOM on GPU: Reduce resolution/steps or use
low_cpu_mem_usage=True; clear cache withtorch.cuda.empty_cache(). - Custom LoRA Invalid: Verify Hugging Face path; must contain model card with
instance_promptor detectable weights/image. - Generation Slow: Turbo mode uses 0.0 CFG; increase steps for quality but expect longer times.
- UI Issues: CSS targets gallery/buttons; set
ssr_mode=Trueif rendering fails. - Diffusers Branch: Uses PR #12790; update via git if conflicts.
Contributions welcome! Fork the repo, add new LoRAs to the loras list, or enhance UI/optimizations, then submit PRs with tests. Ideas:
- More LoRA presets.
- Img2Img support (currently ignored for Turbo).
- Batch generation.
Repository: https://github.com/PRITHIVSAKTHIUR/Z-Image-Turbo-LoRA-DLC.git
Apache License 2.0. See LICENSE for details.
Built by Prithiv Sakthi. Report issues via the repository.