File size: 9,124 Bytes
86421c4
9afe4d4
86421c4
f8896c8
86421c4
 
233cfff
9afe4d4
2e7faf1
 
9afe4d4
44feeef
2e7faf1
 
86421c4
 
 
 
 
 
2fc2e78
6a7d76c
2fc2e78
6a7d76c
 
 
 
 
2fc2e78
 
 
 
6a7d76c
 
2fc2e78
6a7d76c
 
2fc2e78
6a7d76c
 
2fc2e78
 
 
 
 
6a7d76c
 
 
 
 
 
 
 
2fc2e78
6a7d76c
 
 
 
 
 
 
 
 
 
 
 
 
2fc2e78
6a7d76c
 
 
2fc2e78
 
6a7d76c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2fc2e78
6a7d76c
 
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
---
title: CoTyle
emoji: 🎨
colorFrom: gray
colorTo: purple
sdk: gradio
sdk_version: 5.49.1
app_file: app.py
python_version: 3.10
# 移除 license 字段,因为它不是官方支持的字段
gpu: true
suggested_hardware: a100-large
models:
  - Kwai-Kolors/CoTyle
tags:
  - image-generation
  - code-to-style
  - gradio
---


# A Style is Worth One Code: Unlocking Code-to-Style Image Generation with Discrete Style Space
<p align="center"> 
    <a href="xxx"><img alt="Build" src="https://img.shields.io/badge/arXiv-Paper-da282a.svg"></a>
    <a href="https://Kwai-Kolors.github.io/CoTyle/"><img alt="Build" src="https://img.shields.io/badge/Project%20Page-Homepage-yellow"></a> 
    <a href="https://github.com/Kwai-Kolors/CoTyle"><img alt="Build" src="https://img.shields.io/badge/GitHub-Code-f8f0f0.svg"></a> 
    <a href="https://huggingface.co/spaces/Kwai-Kolors/CoTyle"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Demo-32CD32"></a>
    <a href="https://huggingface.co/Kwai-Kolors/Kolors-CoTyle"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Model-fd8b02"></a>
</p>

<p align="center">
    <span style="color:#137cf3; font-family: Gill Sans">Huijie Liu</span><sup>1,2</sup>,
    <span style="color:#137cf3; font-family: Gill Sans">Shuhao Cui</span><sup>2</sup>,
    <span style="color:#137cf3; font-family: Gill Sans">Haoxiang Cao</span><sup>2,3</sup>,
    <span style="color:#137cf3; font-family: Gill Sans">Shuai Ma</span><sup>1</sup>,
    <span style="color:#137cf3; font-family: Gill Sans">Kai Wu</span><sup>2,†</sup>,
    <span style="color:#137cf3; font-family: Gill Sans">Guoliang Kang</span><sup>1,†</sup>
    <br>
    <sup>1</sup><span style="font-size: 16px">Beihang University</span>,
    <sup>2</sup><span style="font-size: 16px">Kolors Team, Kuaishou Technology</span>, 
    <sup>3</sup><span style="font-size: 16px">South China Normal University</span>
    <br>
    <sup>†</sup><span style="font-size: 16px">Co-Corresponding Author</span>
</p>

> This repositories offers official code of paper *"A Style is Worth One Code: Unlocking Code-to-Style Image Generation with Discrete Style Space"*. We offer both Open-Source Version (based on Qwen-Image) and Commercial Version (based on Kolors). If you are a professional developer and interested in further developing CoTyle, please follow the tutorial below. Commercial Version is comming soon.

<p align="center">
<img src="assets/2-fig1_01.png" width=95% height=95% 
class="center">
</p>


## 🔥 News
- [11/13/2025] The [demo](https://huggingface.co/spaces/Kwai-Kolors/CoTyle) of CoTyle-Dev is released on Hugging Face.
- [11/13/2025] The [weights](https://huggingface.co/Kwai-Kolors/Kolors-CoTyle) of CoTyle-Dev are released on Hugging Face.
- [11/13/2025] The [code](https://github.com/Kwai-Kolors/CoTyle) is released!
- [11/13/2025] The [homepage](https://Kwai-Kolors.github.io/CoTyle/) of CoTyle is released.
- [11/13/2025] The [paper](https://xxx) of CoTyle is released.

## 📝 ToDo
- [x] Publish the paper on Arxiv.
- [x] Release the homepage of CoTyle.
- [x] Launch a free demo on Hugging Face Spaces of CoTyle.
- [x] Open source the code and model weights of CoTyle.
- [ ] Release the commercial version of CoTyle.

## 📖 Abstract
Innovative visual stylization is a cornerstone of artistic creation, yet generating novel and consistent visual styles remains a significant challenge. Existing generative approaches typically rely on lengthy textual prompts, reference images, or parameter-efficient fine-tuning to guide style-aware image synthesis, but often struggle with style consistency, limited novelty, and complex style representations. In this paper, we affirm that a style is worth one numerical code by introducing the novel task, code-to-style image generation, which produces images with novel, consistent visual styles conditioned solely on a numerical style code. To date, this field has only been primarily explored by the industry (e.g., Midjourney), with no open-source research from the academic community. To fill this gap,
we propose CoTyle, the first open-source method for this task. Specifically, we first train a discrete style codebook from a collection of images to extract style embeddings. These embeddings are used to condition a text-to-image diffusion model (T2I-DM) for style-consistent generation. Subsequently, we train an autoregressive transformer on the quantized style codes to model their distribution, allowing the synthesis of novel style codes. During inference, a numerical code maps to a unique style sequence,
which guides the diffusion process to produce images in the corresponding style. Unlike existing methods, our approach offers unparalleled simplicity and diversity, unlocking a vast space of reproducible styles from minimal input. Extensive experiments validate that CoTyle effectively turns a numerical code into a style controller, demonstrating a style is worth one code.

## ⚡️ Quick Start
### 🔧 Requirements and Installation
Run the following command to install the requirements.
```bash
git clone https://github.com/Kwai-Kolors/CoTyle
cd CoTyle
conda create -n cotyle python=3.10 
conda activate cotyle
pip install -r requirements.txt
```

### ⏬ Download
Please download the checkpoints and put them to the `./pretrained_models` directory.
You can download them from [Hugging Face](https://huggingface.co/Kwai-Kolors/Kolors-CoTyle/tree/main).
```bash
git lfs install
git clone https://huggingface.co/Kwai-Kolors/Kolors-CoTyle
mv Kolors-CoTyle pretrained_models
```

### 🚄 Code-to-Style Generation
For a quick walkthrough of the inference pipeline, we recommend generating a single image (see Single-Sample Generation), which takes about 20 seconds per image on a single NVIDIA H200 GPU..
To intuitively experience the powerful capabilities of CoTyle, we recommend generating a batch of images (see Batch-Sample Generation), which by default produces 42 images (7 style codes × 6 prompts) in approximately 15 minutes. 



#### Batch-Samples Generation
Run the following command to generate a batch of images. By default, 7 rows and 6 columns of images will be generated, where all images in each row are produced using the same style code, and all images in each column are generated using the same prompt. 
You can adjust the `--style_code` and the content in `./test_prompts.txt` to obtain the desired outputs.

This process may take considerable time. 
Therefore, we provide an accelerated version based on [piFlow](https://github.com/Lakonik/piFlow), which requires only 4 denoising steps; however, this approach produces lower image quality.
Enable `--accelerate` to activate piFlow.
```bash
python inference_batch.py --model_path ./pretrained_models \
  --style_code 1234567 5201314 13415926 886 20010627 996007 2333 \
  --prompt_file_path ./test_prompts.txt \
  --output_path outputs \
  --seed 1024 \
  --accelerate
```

If time permits, we strongly recommend executing the command below.
```bash
python inference_batch.py --model_path ./pretrained_models \
  --style_code 1234567 5201314 13415926 886 20010627 996007 2333 \
  --prompt_file_path ./test_prompts.txt \
  --output_path outputs \
  --seed 1024 \
```

After successful execution, you will obtain the following results:
<p align="center">
<img src="assets/batch_example.png" width=95% height=95% 
class="center">
</p>


#### Single-Sample Generation
Execute the following code for single-sample inference. You can generate desired results by adjusting the `--style_code` and `--prompt`.

```bash
python inference.py --model_path ./pretrained_models \
  --style_code 1234567 \
  --prompt "A lovely crystal snake spirit, slender and nimble, wears an exquisite crystal crown atop its head. Its scales are translucent, shimmering like crystal, its eyes are bright and round, and its expression is lively. Its body coils naturally, its tail gracefully curved, its overall posture harmonious and beautiful." \
  --output_path outputs \
  --seed 1024
```
Similarly, you can enable the `--accelerate` to speed up.

## 📲 Gradio Apps
We provide Gradio apps for interactivate inference with the CoTyle.
Official apps are available on [HuggingFace Spaces](https://huggingface.co/Kwai-Kolors/Kolors-CoTyle)
You can run the fllowing code to use Gradio Apps.
```bash
python app.py
```

Note: The Gradio apps use an accelerated version, which may result in a slight reduction in image generation quality.

<p align="center">
<img src="assets/demo.png" width=95% height=95% 
class="center">
</p>



##  🌟 Citation
If CoTyle is helpful, please help to ⭐ the repo.

If you find this project useful for your research, please consider citing our paper:
```bibtex
@article{liu2025cotyle,
  title={xxx},
  author={xxx},
  journal={arXiv preprint arXiv:xxx},
  year={2025}
}
```

## 💌 Acknowledge
This code builds on [diffusers](https://huggingface.co/docs/diffusers/index), [Qwen-Image](https://github.com/QwenLM/Qwen-Image), [piFlow](https://github.com/Lakonik/piFlow) and [UniTok](https://github.com/FoundationVision/UniTok). Thanks for open-sourcing!