File size: 7,821 Bytes
d4d8b51
 
 
 
 
 
 
 
 
 
 
 
3e2ed1e
 
 
 
 
 
 
 
d4d8b51
38e9221
d4d8b51
38e9221
d4d8b51
38e9221
 
 
 
 
f992259
fe18223
38e9221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe18223
38e9221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe18223
38e9221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe18223
f992259
 
38e9221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
---
title: Minecraftify
emoji: 
colorFrom: blue
colorTo: red
sdk: gradio
sdk_version: 6.18.0
python_version: '3.13'
app_file: app.py
pinned: false
license: apache-2.0
short_description: Mincraftify converts all images into mc-style LIVE!
tags:
  - track:wood
  - sponsor:openai
  - sponsor:modal
  - achievement:offgrid
  - achievement:welltuned
  - achievement:offbrand
  - achievement:fieldnotes
---
# Minecraftify!

**Minecraftify your images live.**

Minecraftify is a Hugging Face Gradio Space that turns uploaded photos into a faithful vanilla Minecraft interpretation of the same scene. It is powered by a fine-tuned **FLUX.2-Klein-4B** img2img LoRA trained on a custom dataset generated with **Qwen-Edit-25-12**.

## Live Demo

* **Space:** Minecraftify
* **Demo video:** [YouTube walkthrough](https://youtu.be/W-2yEjlTOK4)
* **Blog post:** [Project blog](https://huggingface.co/blog/build-small-hackathon/minecraftify)

## Current Status

Playable demo Space with:

* still-image Minecraftification
* live webcam mode
* persistent model caching on Space storage
* LoRA-based FLUX.2-Klein inference
* Gradio UI with image upload, webcam input, and advanced settings

## What It Does

Minecraftify transforms an input image into a Minecraft-style version of the same scene while trying to preserve:

* composition
* camera angle
* layout
* objects already present in the scene
* color relationships and overall structure

The model is tuned to:

* replace realistic surfaces with Minecraft blocks and voxel geometry
* keep the scene recognizable
* avoid unnecessary scene changes
* convert people, animals, and objects into Minecraft-style equivalents where needed

## Project Artifacts

* **Base model:** `black-forest-labs/FLUX.2-klein-4B`
* **LoRA adapter:** `AnimeOverlord/flux2-klein-4b-mc-v2`
* **Dataset:** 376 image pairs created with Qwen-Edit-25-12
* **Training script:** `train_dreambooth_lora_flux2_klein_img2img.py`

## Fine-Tuning Setup

The LoRA was trained with FLUX.2-Klein img2img using a paired dataset with:

* `source_image` as the conditioning image
* `edited_image` as the target image
* `prompt_used` as the caption column

Training highlights:

* `train_batch_size=1`
* `gradient_accumulation_steps=4`
* `mixed_precision=bf16`
* `learning_rate=2e-6`
* `lr_scheduler=constant_with_warmup`
* `lr_warmup_steps=200`
* `max_train_steps=1200`
* `rank=64`
* `cache_latents`
* `use_8bit_adam`
* `aspect_ratio_buckets` enabled

## Hackathon Fit

Minecraftify is designed as a compact, fun, image-to-image Space with a strong visual identity and an immediate demo loop.

It fits the small-model spirit because the core generation path is built around a **4B FLUX Klein model** with a LoRA adapter rather than a large general-purpose model.

## How to Demo

1. Upload an image or start the webcam.
2. Choose still image or live mode.
3. Adjust inference steps, guidance scale, and seed.
4. Click **Minecraftify!**
5. Download or inspect the result.

## Recommended Demo Settings

* **Inference steps:** 3
* **Guidance scale:** 3.0
* **Seed:** any fixed value for reproducibility
* **Input:** well-lit images with clear objects and simple scenes

## Features

* image upload
* webcam capture
* live frame processing
* prompt-based scene preservation
* persistent model caching in Hugging Face Space storage
* adjustable inference settings
* output comparison view

## Model and Runtime

The app loads the FLUX.2-Klein base model and then applies the Minecraft LoRA adapter.

Runtime behavior:

* models are cached on persistent Space storage
* weights are reused across runs when present
* the pipeline is kept in memory for the active session
* image generation uses img2img inference for scene preservation

## Space Storage

This Space is configured to use persistent storage so model files do not need to be downloaded every time the Space restarts.

* model cache path: `/data/models`
* Hugging Face cache path: `/data/.huggingface`

## Architecture

**Input image****FLUX.2-Klein img2img****Minecraft LoRA****Rendered output**

For live mode, webcam frames are captured continuously and only the latest frame is processed when the model becomes available.

## Local Development

This project was trained locally with PyTorch and Accelerate, and the training workflow also supports pushing the fine-tuned model to the Hugging Face Hub.

### Running locally with PyTorch

#### 1) Install the training dependencies

For the most up-to-date Diffusers example scripts, it is recommended to install Diffusers from source:

```bash
git clone https://github.com/huggingface/diffusers
cd diffusers
pip install -e .
````

Then install the FLUX DreamBooth example requirements:

```bash
cd examples/dreambooth
pip install -r requirements_flux.txt
```

#### 2) Configure Accelerate

Set up Accelerate for your environment:

```bash
accelerate config
```

If you want the default configuration without answering prompts:

```bash
accelerate config default
```

If you are running in a notebook or another environment without an interactive shell:

```python
from accelerate.utils import write_basic_config
write_basic_config()
```

If possible, enable `torch compile` in Accelerate for faster training. Also make sure `peft>=0.6.0` is installed, since PEFT is used as the LoRA backend.

### Training FLUX.2-Klein LoRA on an image-to-image dataset

This project uses the FLUX 2 Klein 4B base model and trains a LoRA adapter on a paired img2img dataset.

```bash
cd diffusers/examples/dreambooth && accelerate launch train_dreambooth_lora_flux2_klein_img2img.py \
  --pretrained_model_name_or_path=black-forest-labs/FLUX.2-klein-4B \
  --output_dir="flux2-i2i" \
  --dataset_name="AnimeOverlord/mine-dataset" \
  --image_column="edited_image" \
  --cond_image_column="source_image" \
  --caption_column="prompt_used" \
  --gradient_checkpointing \
  --cache_latents \
  --train_batch_size=1 \
  --guidance_scale=1 \
  --gradient_accumulation_steps=4 \
  --mixed_precision="bf16" \
  --optimizer="prodigy" \
  --learning_rate=1 \
  --lr_warmup_steps=200 \
  --max_train_steps=1200 \
  --rank=64 \
  --seed="0" \
  --push_to_hub \
  --hub_model_id="[YOURACCOUNT]/flux2-klein-4b-mc" \
  --aspect_ratio_buckets="672,1568;688,1504;720,1456;752,1392;800,1328;832,1248;880,1184;944,1104;1024,1024;1104,944;1184,880;1248,832;1328,800;1392,752;1456,720;1504,688;1568,672"
```

### Notes

* The dataset contains **376 images** created with **Qwen-Edit-25-12**.
* The training run uses a paired img2img setup with:

  * `source_image` as the conditioning image
  * `edited_image` as the target image
  * `prompt_used` as the caption
* `push_to_hub` uploads the trained LoRA adapter to the Hugging Face Hub.
* The aspect-ratio buckets help keep training efficient across different image shapes.

### Output

After training, the LoRA adapter is published to:

```bash
YOURACCOUNT/flux2-klein-4b-mc
```

## Blog and Video Links

* **Blog:** [Read the build notes](https://huggingface.co/blog/build-small-hackathon/minecraftify)
* **YouTube:** [Watch the walkthrough](https://youtu.be/W-2yEjlTOK4)
* **LinkedIn Post** [Read the social media post](https://www.linkedin.com/posts/md-abdul-kalam-khan_ai-machinelearning-generativeai-ugcPost-7472386161223680000-PdaN/)

## Link to Notebooks Used
* **Training Notbook:** [Modal Notebook](https://modal.com/notebooks/kalamkhan-se/main/nb-ygLQVGDvJR3FbrNpQwGYfV)
* **Data Creation Notebook:** [Modal Notebook](https://modal.com/notebooks/kalamkhan-se/main/nb-L22FAz1tYTB39h7tXkXF4N)

## Credits

* Base model: Black Forest Labs
* Fine-tuning workflow: Hugging Face Diffusers
* Dataset creation: Qwen-Edit-25-12
* UI: Gradio

## License

This project is a demo Space for experimentation and presentation. Check the model and dataset licenses before redistribution.