Spaces:
Running
on
Zero
Running
on
Zero
Update title, subtitle, and tags
Browse files
README.md
CHANGED
|
@@ -1,190 +1,105 @@
|
|
| 1 |
---
|
| 2 |
-
title: Z
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
-
pinned:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
# Z
|
| 13 |
-
|
| 14 |
-
A production-ready, optimized image generation and transformation application built with Gradio and Diffusers. This application addresses common production challenges including error handling, resource management, and performance optimization.
|
| 15 |
-
|
| 16 |
-
## π Features
|
| 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 |
-
## π Troubleshooting
|
| 75 |
-
|
| 76 |
-
### Common Issues
|
| 77 |
-
|
| 78 |
-
#### 1. "Out of Memory" Error
|
| 79 |
-
**Solution**: The app automatically handles OOM scenarios and suggests:
|
| 80 |
-
- Using smaller image sizes
|
| 81 |
-
- Enabling CPU offloading
|
| 82 |
-
- Restarting the space
|
| 83 |
-
|
| 84 |
-
#### 2. "Could not compile UNet" Warning
|
| 85 |
-
**Expected Behavior**: This is normal for PyTorch < 2.0. The app continues without compilation.
|
| 86 |
-
|
| 87 |
-
#### 3. "Could not enable xformers" Warning
|
| 88 |
-
**Expected Behavior**: Falls back to standard attention mechanism.
|
| 89 |
-
|
| 90 |
-
#### 4. Slow Generation
|
| 91 |
-
**Check**:
|
| 92 |
-
- GPU memory availability
|
| 93 |
-
- Model loading status
|
| 94 |
-
- System resource usage
|
| 95 |
-
|
| 96 |
-
### Logs
|
| 97 |
-
The application logs to:
|
| 98 |
-
- Console output for real-time monitoring
|
| 99 |
-
- `z_image_turbo.log` file for persistent logs
|
| 100 |
-
|
| 101 |
-
## π― Best Practices
|
| 102 |
-
|
| 103 |
-
### For Users
|
| 104 |
-
1. **Start with simple prompts** to test performance
|
| 105 |
-
2. **Use appropriate image sizes** for your hardware
|
| 106 |
-
3. **Leverage caching** by reusing similar prompts
|
| 107 |
-
4. **Monitor system resources** in the System Monitor tab
|
| 108 |
-
|
| 109 |
-
### For Developers
|
| 110 |
-
1. **Check error codes** for debugging
|
| 111 |
-
2. **Monitor performance metrics** regularly
|
| 112 |
-
3. **Use the health check endpoint** for monitoring
|
| 113 |
-
4. **Review logs** for troubleshooting
|
| 114 |
-
|
| 115 |
-
## π Error Codes
|
| 116 |
-
|
| 117 |
-
| Code | Meaning | Resolution |
|
| 118 |
-
|------|---------|------------|
|
| 119 |
-
| 1001 | Model Load Error | Check model access and permissions |
|
| 120 |
-
| 1002 | Generation Error | Check prompt and resources |
|
| 121 |
-
| 1003 | Transform Error | Verify input image and prompt |
|
| 122 |
-
| 2001 | Invalid Input | Check input parameters |
|
| 123 |
-
| 3001 | Resource Error | Free up memory or use smaller images |
|
| 124 |
-
| 4001 | Network Error | Check internet connection |
|
| 125 |
-
| 5001 | Cache Error | Clear cache or restart |
|
| 126 |
-
| 9999 | Unknown Error | Check logs for details |
|
| 127 |
-
|
| 128 |
-
## π Performance Optimization
|
| 129 |
-
|
| 130 |
-
### Automatic Optimizations
|
| 131 |
-
1. **Model Compilation**: PyTorch 2.0+ compilation when available
|
| 132 |
-
2. **Memory Efficiency**: xformers attention and VAE slicing
|
| 133 |
-
3. **Resource Management**: CPU offloading for memory constraints
|
| 134 |
-
4. **Smart Caching**: LRU cache with intelligent eviction
|
| 135 |
-
|
| 136 |
-
### Manual Tuning
|
| 137 |
-
- Adjust `max_size` in CacheManager for memory/concurrency balance
|
| 138 |
-
- Modify inference steps for quality/speed trade-off
|
| 139 |
-
- Use aspect ratios that match your hardware capabilities
|
| 140 |
-
|
| 141 |
-
## π Security
|
| 142 |
-
|
| 143 |
-
### Best Practices
|
| 144 |
-
- No user data is persisted beyond cache TTL
|
| 145 |
-
- Images are not stored permanently
|
| 146 |
-
- API keys are environment variables only
|
| 147 |
-
- Safe tensor format for model weights
|
| 148 |
-
|
| 149 |
-
## π Changelog
|
| 150 |
-
|
| 151 |
-
### v2.0.0 Production
|
| 152 |
-
- **Added**: Comprehensive error handling with error codes
|
| 153 |
-
- **Added**: PyTorch 2.0+ compilation with fallback
|
| 154 |
-
- **Added**: xformers optimization with CPU fallback
|
| 155 |
-
- **Added**: Intelligent caching system with LRU and TTL
|
| 156 |
-
- **Added**: Real-time system monitoring
|
| 157 |
-
- **Added**: Production-ready logging
|
| 158 |
-
- **Added**: Health check endpoints
|
| 159 |
-
- **Improved**: Resource management and cleanup
|
| 160 |
-
- **Improved**: User experience with better error messages
|
| 161 |
-
- **Improved**: Performance with automatic optimizations
|
| 162 |
-
|
| 163 |
-
### v1.0.0 Initial
|
| 164 |
-
- Basic image generation
|
| 165 |
-
- Simple UI
|
| 166 |
-
- Model integration
|
| 167 |
-
|
| 168 |
-
## π€ Contributing
|
| 169 |
-
|
| 170 |
-
When contributing:
|
| 171 |
-
1. Follow PEP 8 style guidelines
|
| 172 |
-
2. Add comprehensive error handling
|
| 173 |
-
3. Include logging for debugging
|
| 174 |
-
4. Update documentation
|
| 175 |
-
5. Test with various hardware configurations
|
| 176 |
-
|
| 177 |
-
## π License
|
| 178 |
-
|
| 179 |
-
This project is licensed under the MIT License.
|
| 180 |
-
|
| 181 |
-
## π Acknowledgments
|
| 182 |
-
|
| 183 |
-
- [Tongyi-MAI/Z-Image-Turbo](https://huggingface.co/Tongyi-MAI/Z-Image-Turbo) for the base model
|
| 184 |
-
- [Diffusers](https://github.com/huggingface/diffusers) library
|
| 185 |
-
- [Gradio](https://github.com/gradio-app/gradio) for the UI framework
|
| 186 |
-
- Hugging Face Spaces for hosting
|
| 187 |
|
| 188 |
---
|
| 189 |
|
| 190 |
-
**Created
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Z-Image Turbo + GLM-4.6V / DeepSeek-3.2 Thinking
|
| 3 |
+
emoji: π¨
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.31.0
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
tags:
|
| 12 |
+
- text-to-image
|
| 13 |
+
- image-to-image
|
| 14 |
+
- diffusion
|
| 15 |
+
- transformer
|
| 16 |
+
- z-image
|
| 17 |
+
- z-image-turbo
|
| 18 |
+
- ai-art
|
| 19 |
+
- image-generation
|
| 20 |
+
- image-editing
|
| 21 |
+
- glm-4
|
| 22 |
+
- glm-4.6v
|
| 23 |
+
- glm-4v
|
| 24 |
+
- vision-language
|
| 25 |
+
- multimodal
|
| 26 |
+
- prompt-generation
|
| 27 |
+
- ai-assistant
|
| 28 |
+
- zhipu
|
| 29 |
+
- zai
|
| 30 |
+
- deepseek
|
| 31 |
+
- deepseek-reasoner
|
| 32 |
+
- deepseek-3.2
|
| 33 |
+
- thinking
|
| 34 |
+
- reasoning
|
| 35 |
+
- multilingual
|
| 36 |
+
- rtl
|
| 37 |
+
- arabic
|
| 38 |
+
- hindi
|
| 39 |
+
- spanish
|
| 40 |
+
- portuguese
|
| 41 |
+
short_description: Image Gen & Edit with GLM-4.6V + DeepSeek-3.2
|
| 42 |
---
|
| 43 |
|
| 44 |
+
# β‘ Z-Image Generation & Transformation Demo
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
Generate stunning AI images and transform existing photos using **Alibaba's Z-Image-Turbo** - a next-generation diffusion transformer model.
|
| 47 |
+
|
| 48 |
+
## β¨ Features
|
| 49 |
+
|
| 50 |
+
π¨ **Text-to-Image Generation**
|
| 51 |
+
- 10 style presets (Photorealistic, Cinematic, Anime, Digital Art, and more)
|
| 52 |
+
- 18 aspect ratios from 1024px to 2048px
|
| 53 |
+
- AI-powered prompt polishing with Qwen2.5-72B
|
| 54 |
+
|
| 55 |
+
πΌοΈ **Image-to-Image Transformation**
|
| 56 |
+
- Transform photos into different art styles
|
| 57 |
+
- Adjustable strength control (subtle to complete change)
|
| 58 |
+
- Style-focused AI prompt enhancement
|
| 59 |
+
|
| 60 |
+
β‘ **Optimized Performance**
|
| 61 |
+
- Runs on ZeroGPU (NVIDIA H200)
|
| 62 |
+
- FlashAttention-2 via SDPA
|
| 63 |
+
- ~20-25 seconds per generation
|
| 64 |
+
|
| 65 |
+
## π How to Use
|
| 66 |
+
|
| 67 |
+
### Generate Tab
|
| 68 |
+
1. Enter a description of your image
|
| 69 |
+
2. (Optional) Enable "Polish Prompt" for AI-enhanced prompts
|
| 70 |
+
3. Select a style and aspect ratio
|
| 71 |
+
4. Click "Generate"
|
| 72 |
+
|
| 73 |
+
### Transform Tab
|
| 74 |
+
1. Upload an image
|
| 75 |
+
2. Describe the transformation you want
|
| 76 |
+
3. Adjust strength (lower = subtle, higher = dramatic)
|
| 77 |
+
4. Click "Transform"
|
| 78 |
+
|
| 79 |
+
## π― Example Prompts
|
| 80 |
+
|
| 81 |
+
- *"Ancient dragon perched on a Gothic cathedral at dusk, stormy purple sky"*
|
| 82 |
+
- *"Cyberpunk samurai in a neon-lit rainy alley, glowing armor"*
|
| 83 |
+
- *"Cozy witch cottage interior, cauldrons bubbling, magical atmosphere"*
|
| 84 |
+
|
| 85 |
+
## π Technical Details
|
| 86 |
+
|
| 87 |
+
| Spec | Value |
|
| 88 |
+
|------|-------|
|
| 89 |
+
| Model | Tongyi-MAI/Z-Image-Turbo |
|
| 90 |
+
| Steps | 9 (optimized) |
|
| 91 |
+
| Precision | BFloat16 |
|
| 92 |
+
| Max Resolution | 2048x2048 |
|
| 93 |
+
|
| 94 |
+
## π Links
|
| 95 |
+
|
| 96 |
+
- [Z-Image-Turbo Model](https://huggingface.co/Tongyi-MAI/Z-Image-Turbo)
|
| 97 |
+
- [Z-Image GitHub](https://github.com/Tongyi-MAI/Z-Image)
|
| 98 |
+
|
| 99 |
+
## π License
|
| 100 |
+
|
| 101 |
+
Model: Apache 2.0 License
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
---
|
| 104 |
|
| 105 |
+
**Created by [@lulavc](https://huggingface.co/lulavc)**
|