AnimeOverlord commited on
Commit
38e9221
·
1 Parent(s): ba21ca9

new update fix

Browse files
Files changed (2) hide show
  1. README.md +234 -3
  2. app.py +8 -11
README.md CHANGED
@@ -11,8 +11,239 @@ pinned: false
11
  license: apache-2.0
12
  short_description: Mincraftify converts all images into mc-style LIVE!
13
  ---
 
14
 
15
- # ⛏️ Minecraft Spatial Voxel Filter
16
- Real-time video stream processing pipeline using FastRTC and Modal serverless environments.
17
 
18
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  license: apache-2.0
12
  short_description: Mincraftify converts all images into mc-style LIVE!
13
  ---
14
+ # Minecraftify!
15
 
16
+ **Minecraftify your images live.**
 
17
 
18
+ 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**.
19
+
20
+ ## Live Demo
21
+
22
+ * **Space:** Minecraftify
23
+ * **Demo video:** [YouTube walkthrough](#)
24
+ * **Blog post:** [Project blog](#)
25
+
26
+ ## Current Status
27
+
28
+ Playable demo Space with:
29
+
30
+ * still-image Minecraftification
31
+ * live webcam mode
32
+ * persistent model caching on Space storage
33
+ * LoRA-based FLUX.2-Klein inference
34
+ * Gradio UI with image upload, webcam input, and advanced settings
35
+
36
+ ## What It Does
37
+
38
+ Minecraftify transforms an input image into a Minecraft-style version of the same scene while trying to preserve:
39
+
40
+ * composition
41
+ * camera angle
42
+ * layout
43
+ * objects already present in the scene
44
+ * color relationships and overall structure
45
+
46
+ The model is tuned to:
47
+
48
+ * replace realistic surfaces with Minecraft blocks and voxel geometry
49
+ * keep the scene recognizable
50
+ * avoid unnecessary scene changes
51
+ * convert people, animals, and objects into Minecraft-style equivalents where needed
52
+
53
+ ## Project Artifacts
54
+
55
+ * **Base model:** `black-forest-labs/FLUX.2-klein-4B`
56
+ * **LoRA adapter:** `AnimeOverlord/flux2-klein-4b-mc-v2`
57
+ * **Dataset:** 400 image pairs created with Qwen-Edit-25-12
58
+ * **Training script:** `train_dreambooth_lora_flux2_klein_img2img.py`
59
+
60
+ ## Fine-Tuning Setup
61
+
62
+ The LoRA was trained with FLUX.2-Klein img2img using a paired dataset with:
63
+
64
+ * `source_image` as the conditioning image
65
+ * `edited_image` as the target image
66
+ * `prompt_used` as the caption column
67
+
68
+ Training highlights:
69
+
70
+ * `train_batch_size=1`
71
+ * `gradient_accumulation_steps=4`
72
+ * `mixed_precision=bf16`
73
+ * `learning_rate=2e-6`
74
+ * `lr_scheduler=constant_with_warmup`
75
+ * `lr_warmup_steps=200`
76
+ * `max_train_steps=1200`
77
+ * `rank=64`
78
+ * `cache_latents`
79
+ * `use_8bit_adam`
80
+ * `aspect_ratio_buckets` enabled
81
+
82
+ ## Hackathon Fit
83
+
84
+ Minecraftify is designed as a compact, fun, image-to-image Space with a strong visual identity and an immediate demo loop.
85
+
86
+ 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.
87
+
88
+ ## How to Demo
89
+
90
+ 1. Upload an image or start the webcam.
91
+ 2. Choose still image or live mode.
92
+ 3. Adjust inference steps, guidance scale, and seed.
93
+ 4. Click **Minecraftify!**
94
+ 5. Download or inspect the result.
95
+
96
+ ## Recommended Demo Settings
97
+
98
+ * **Inference steps:** 3
99
+ * **Guidance scale:** 3.0
100
+ * **Seed:** any fixed value for reproducibility
101
+ * **Input:** well-lit images with clear objects and simple scenes
102
+
103
+ ## Features
104
+
105
+ * image upload
106
+ * webcam capture
107
+ * live frame processing
108
+ * prompt-based scene preservation
109
+ * persistent model caching in Hugging Face Space storage
110
+ * adjustable inference settings
111
+ * output comparison view
112
+
113
+ ## Model and Runtime
114
+
115
+ The app loads the FLUX.2-Klein base model and then applies the Minecraft LoRA adapter.
116
+
117
+ Runtime behavior:
118
+
119
+ * models are cached on persistent Space storage
120
+ * weights are reused across runs when present
121
+ * the pipeline is kept in memory for the active session
122
+ * image generation uses img2img inference for scene preservation
123
+
124
+ ## Space Storage
125
+
126
+ This Space is configured to use persistent storage so model files do not need to be downloaded every time the Space restarts.
127
+
128
+ * model cache path: `/data/models`
129
+ * Hugging Face cache path: `/data/.huggingface`
130
+
131
+ ## Architecture
132
+
133
+ **Input image** → **FLUX.2-Klein img2img** → **Minecraft LoRA** → **Rendered output**
134
+
135
+ For live mode, webcam frames are captured continuously and only the latest frame is processed when the model becomes available.
136
+
137
+ ## Local Development
138
+
139
+ 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.
140
+
141
+ ### Running locally with PyTorch
142
+
143
+ #### 1) Install the training dependencies
144
+
145
+ For the most up-to-date Diffusers example scripts, it is recommended to install Diffusers from source:
146
+
147
+ ```bash
148
+ git clone https://github.com/huggingface/diffusers
149
+ cd diffusers
150
+ pip install -e .
151
+ ````
152
+
153
+ Then install the FLUX DreamBooth example requirements:
154
+
155
+ ```bash
156
+ cd examples/dreambooth
157
+ pip install -r requirements_flux.txt
158
+ ```
159
+
160
+ #### 2) Configure Accelerate
161
+
162
+ Set up Accelerate for your environment:
163
+
164
+ ```bash
165
+ accelerate config
166
+ ```
167
+
168
+ If you want the default configuration without answering prompts:
169
+
170
+ ```bash
171
+ accelerate config default
172
+ ```
173
+
174
+ If you are running in a notebook or another environment without an interactive shell:
175
+
176
+ ```python
177
+ from accelerate.utils import write_basic_config
178
+ write_basic_config()
179
+ ```
180
+
181
+ 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.
182
+
183
+ ### Training FLUX.2-Klein LoRA on an image-to-image dataset
184
+
185
+ This project uses the FLUX 2 Klein 4B base model and trains a LoRA adapter on a paired img2img dataset.
186
+
187
+ ```bash
188
+ cd diffusers/examples/dreambooth && accelerate launch train_dreambooth_lora_flux2_klein_img2img.py \
189
+ --pretrained_model_name_or_path=black-forest-labs/FLUX.2-klein-4B \
190
+ --output_dir="flux2-i2i" \
191
+ --dataset_name="AnimeOverlord/mine-dataset" \
192
+ --image_column="edited_image" \
193
+ --cond_image_column="source_image" \
194
+ --caption_column="prompt_used" \
195
+ --gradient_checkpointing \
196
+ --cache_latents \
197
+ --train_batch_size=1 \
198
+ --guidance_scale=1 \
199
+ --gradient_accumulation_steps=4 \
200
+ --mixed_precision="bf16" \
201
+ --optimizer="prodigy" \
202
+ --learning_rate=1 \
203
+ --lr_warmup_steps=200 \
204
+ --max_train_steps=1200 \
205
+ --rank=64 \
206
+ --seed="0" \
207
+ --push_to_hub \
208
+ --hub_model_id="[YOURACCOUNT]/flux2-klein-4b-mc" \
209
+ --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"
210
+ ```
211
+
212
+ ### Notes
213
+
214
+ * The dataset contains **400 images** created with **Qwen-Edit-25-12**.
215
+ * The training run uses a paired img2img setup with:
216
+
217
+ * `source_image` as the conditioning image
218
+ * `edited_image` as the target image
219
+ * `prompt_used` as the caption
220
+ * `push_to_hub` uploads the trained LoRA adapter to the Hugging Face Hub.
221
+ * The aspect-ratio buckets help keep training efficient across different image shapes.
222
+
223
+ ### Output
224
+
225
+ After training, the LoRA adapter is published to:
226
+
227
+ ```bash
228
+ YOURACCOUNT/flux2-klein-4b-mc
229
+ ```
230
+
231
+ ## Blog and Video Links
232
+
233
+ * **Blog:** [Read the build notes](#)
234
+ * **YouTube:** [Watch the walkthrough](#)
235
+
236
+ ## Link to Notebooks Used
237
+ * **Training Notbook:** [Modal Notebook](https://modal.com/notebooks/kalamkhan-se/main/nb-ygLQVGDvJR3FbrNpQwGYfV)
238
+ * **Data Creation Notebook:** [Modal Notebook](https://modal.com/notebooks/kalamkhan-se/main/nb-L22FAz1tYTB39h7tXkXF4N)
239
+
240
+ ## Credits
241
+
242
+ * Base model: Black Forest Labs
243
+ * Fine-tuning workflow: Hugging Face Diffusers
244
+ * Dataset creation: Qwen-Edit-25-12
245
+ * UI: Gradio
246
+
247
+ ## License
248
+
249
+ This project is a demo Space for experimentation and presentation. Check the model and dataset licenses before redistribution.
app.py CHANGED
@@ -643,7 +643,7 @@ input[type="range"]::-webkit-slider-thumb {
643
  # ----------------------------------------------------------------------
644
 
645
  BASE_MODEL_ID = "black-forest-labs/FLUX.2-klein-4B"
646
- LORA_ID = "AnimeOverlord/flux2-klein-4b-mc"
647
 
648
  # Mount this path in the Space settings
649
  SPACE_DATA_DIR = "/data"
@@ -1000,14 +1000,11 @@ with gr.Blocks(**BLOCKS_KWARGS) as demo:
1000
 
1001
  with gr.Accordion("⚙️ Advanced Settings", open=False):
1002
  steps = gr.Slider(
1003
- minimum=2, maximum=15, value=3, step=1,
1004
  label="⚡ Inference Steps",
1005
  info="Higher = better quality, slower generation",
1006
  )
1007
- guidance_scale = gr.Slider(
1008
- minimum=1.0, maximum=10.0, value=3.0, step=0.5,
1009
- label="🧭 Guidance Scale",
1010
- )
1011
  seed = gr.Number(
1012
  value=42, precision=0,
1013
  label="🎲 Seed",
@@ -1029,12 +1026,12 @@ with gr.Blocks(**BLOCKS_KWARGS) as demo:
1029
 
1030
  # ── RIGHT: Output Column ──
1031
  with gr.Column(scale=5):
1032
- gr.HTML('<div class="mc-section-label"><span class="mc-icon">🧱</span> MINECRAFT VERSION</div>')
1033
 
1034
  with gr.Group(elem_classes="mc-panel"):
1035
  output_image = gr.Image(
1036
  type="pil",
1037
- label="Minecraft version",
1038
  interactive=False,
1039
  height=400,
1040
  )
@@ -1045,7 +1042,7 @@ with gr.Blocks(**BLOCKS_KWARGS) as demo:
1045
  <div class="mc-tip-title">📖 TIPS & TRICKS</div>
1046
  <div class="mc-divider" style="margin: 10px 0;"></div>
1047
  <ul style="padding-left: 20px; margin: 8px 0;">
1048
- <li>🎯 <strong style="color:#7CB342;">Inference steps:</strong> 3 is the sweet spot. Go higher for more detail.</li>
1049
  <li>🐺 <strong style="color:#7CB342;">Still too real?</strong> Describe tricky parts in the details box (e.g. "convert the dog into a wolf mob").</li>
1050
  <li>⏱️ <strong style="color:#7CB342;">Live mode:</strong> The camera stream prioritizes the newest frame whenever the model is free.</li>
1051
  <li>🎲 <strong style="color:#7CB342;">Variations:</strong> Change the seed to get different Minecraft interpretations of the same photo.</li>
@@ -1079,7 +1076,7 @@ with gr.Blocks(**BLOCKS_KWARGS) as demo:
1079
 
1080
  run_btn.click(
1081
  fn=minecraftify,
1082
- inputs=[input_image, steps, guidance_scale, seed, extra_details],
1083
  outputs=output_image,
1084
  )
1085
 
@@ -1092,7 +1089,7 @@ with gr.Blocks(**BLOCKS_KWARGS) as demo:
1092
  queue=False,
1093
  ).then(
1094
  fn=minecraftify_live_loop,
1095
- inputs=[steps, guidance_scale, seed, extra_details],
1096
  outputs=[output_image],
1097
  concurrency_limit=1,
1098
  )
 
643
  # ----------------------------------------------------------------------
644
 
645
  BASE_MODEL_ID = "black-forest-labs/FLUX.2-klein-4B"
646
+ LORA_ID = "AnimeOverlord/flux2-klein-4b-mc-v2"
647
 
648
  # Mount this path in the Space settings
649
  SPACE_DATA_DIR = "/data"
 
1000
 
1001
  with gr.Accordion("⚙️ Advanced Settings", open=False):
1002
  steps = gr.Slider(
1003
+ minimum=1, maximum=15, value=2, step=1,
1004
  label="⚡ Inference Steps",
1005
  info="Higher = better quality, slower generation",
1006
  )
1007
+
 
 
 
1008
  seed = gr.Number(
1009
  value=42, precision=0,
1010
  label="🎲 Seed",
 
1026
 
1027
  # ── RIGHT: Output Column ──
1028
  with gr.Column(scale=5):
1029
+ gr.HTML('<div class="mc-section-label"><span class="mc-icon">🧱</span> MINECRAFT STYLE</div>')
1030
 
1031
  with gr.Group(elem_classes="mc-panel"):
1032
  output_image = gr.Image(
1033
  type="pil",
1034
+ label="Minecraft Style",
1035
  interactive=False,
1036
  height=400,
1037
  )
 
1042
  <div class="mc-tip-title">📖 TIPS & TRICKS</div>
1043
  <div class="mc-divider" style="margin: 10px 0;"></div>
1044
  <ul style="padding-left: 20px; margin: 8px 0;">
1045
+ <li>🎯 <strong style="color:#7CB342;">Inference steps:</strong> 2 is the sweet spot. Go higher for more detail and Craziness!</li>
1046
  <li>🐺 <strong style="color:#7CB342;">Still too real?</strong> Describe tricky parts in the details box (e.g. "convert the dog into a wolf mob").</li>
1047
  <li>⏱️ <strong style="color:#7CB342;">Live mode:</strong> The camera stream prioritizes the newest frame whenever the model is free.</li>
1048
  <li>🎲 <strong style="color:#7CB342;">Variations:</strong> Change the seed to get different Minecraft interpretations of the same photo.</li>
 
1076
 
1077
  run_btn.click(
1078
  fn=minecraftify,
1079
+ inputs=[input_image, steps, 1.0, seed, extra_details],
1080
  outputs=output_image,
1081
  )
1082
 
 
1089
  queue=False,
1090
  ).then(
1091
  fn=minecraftify_live_loop,
1092
+ inputs=[steps, 1.0, seed, extra_details],
1093
  outputs=[output_image],
1094
  concurrency_limit=1,
1095
  )