AnimeOverlord commited on
Commit
093bdef
·
1 Parent(s): ce5c4d4
Files changed (3) hide show
  1. .gitattributes +0 -35
  2. README.md +1 -18
  3. backend/backend.py +0 -127
.gitattributes DELETED
@@ -1,35 +0,0 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -1,18 +1 @@
1
- ---
2
- title: Minecraftify
3
- emoji: ⚡
4
- colorFrom: blue
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 6.18.0
8
- python_version: '3.13'
9
- app_file: app.py
10
- 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
 
1
+ # Minecrafity
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
backend/backend.py DELETED
@@ -1,127 +0,0 @@
1
- import io
2
- import os
3
- import modal
4
-
5
- # ==============================================================================
6
- # 💾 0. CACHE VOLUME SETUP
7
- # ==============================================================================
8
- # This creates a persistent volume that survives between container cold-starts.
9
- cache_volume = modal.Volume.from_name("flux-inductor-cache", create_if_missing=True)
10
- CACHE_DIR = "/root/.cache/torch/inductor"
11
-
12
- # Define container environment
13
- image = (
14
- modal.Image.debian_slim(python_version="3.12")
15
- .pip_install(
16
- "diffusers",
17
- "transformers",
18
- "accelerate",
19
- "pillow",
20
- "torch",
21
- "triton" # Essential for torch.compile
22
- )
23
- # Tell PyTorch Inductor to write its cache to our persistent volume directory
24
- .env({"TORCHINDUCTOR_CACHE_DIR": CACHE_DIR})
25
- )
26
-
27
- app = modal.App("flux-klein-voxel-backend", image=image)
28
-
29
- # ==============================================================================
30
- # 🏎️ 1. THE DEMO PIPELINE (FALLBACK ROUTE)
31
- # ==============================================================================
32
- @app.function()
33
- def demo_stream_frame(img_bytes: bytes) -> bytes:
34
- """Fallback route structurally aligned to match the frontend signature."""
35
- from PIL import Image, ImageDraw
36
-
37
- input_image = Image.open(io.BytesIO(img_bytes)).convert("RGB")
38
- draw = ImageDraw.Draw(input_image)
39
- draw.text((20, 20), "🛠️ WEBRTC PASSTHROUGH DEMO ACTIVE", fill=(0, 255, 0))
40
-
41
- output_buffer = io.BytesIO()
42
- input_image.save(output_buffer, format="JPEG", quality=85)
43
- return output_buffer.getvalue()
44
-
45
-
46
- # ==============================================================================
47
- # 🚀 2. THE REAL-TIME VOXEL ENGINE
48
- # ==============================================================================
49
- @app.cls(
50
- gpu="A10G",
51
- secrets=[modal.Secret.from_name("huggingface-secret")],
52
- max_containers=5,
53
- # Mount the persistent cache volume to the exact path PyTorch is looking at
54
- volumes={CACHE_DIR: cache_volume}
55
- )
56
- class VoxelModel:
57
-
58
- @modal.enter()
59
- def load_pipeline(self):
60
- import torch
61
- from PIL import Image
62
- from diffusers import AutoPipelineForImage2Image
63
-
64
- model_id = "AnimeOverlord/flux2-klein-4b-mc"
65
-
66
- self.pipe = AutoPipelineForImage2Image.from_pretrained(
67
- model_id,
68
- torch_dtype=torch.bfloat16,
69
- token=os.environ["HF_TOKEN"] # Modernized from use_auth_token
70
- )
71
- self.pipe.to("cuda")
72
- self.pipe.enable_attention_slicing()
73
-
74
- # ---------------------------------------------------------
75
- # ✨ COMPILE AND OPTIMIZE THE INFRASTRUCTURE
76
- # ---------------------------------------------------------
77
- print("Initializing torch.compile optimization loops...")
78
-
79
- # Channels-last optimization applied exclusively to the VAE (CNN-based)
80
- self.pipe.vae.to(memory_format=torch.channels_last)
81
-
82
- # Compile the heaviest part of the FLUX architecture safely without memory layout issues
83
- self.pipe.transformer = torch.compile(
84
- self.pipe.transformer,
85
- mode="reduce-overhead", # Trades a bit of compile time for faster inference
86
- fullgraph=False
87
- )
88
-
89
- # WARMUP RUN: Force a dummy inference immediately execution starts.
90
- # If the cache is empty (first run), this traces the graph and saves to the Modal Volume.
91
- # If the cache exists, it instantly hotloads from the Volume.
92
- print("Running warmup to build/load inductor cache...")
93
- dummy_image = Image.new("RGB", (512, 512), (0, 0, 0))
94
- with torch.inference_mode():
95
- self.pipe(
96
- prompt="warmup pass",
97
- image=dummy_image,
98
- strength=0.5,
99
- num_inference_steps=2,
100
- guidance_scale=1.0,
101
- )
102
- print("Warmup complete. Ready for real-time requests!")
103
-
104
- @modal.method()
105
- def process_frame(self, img_bytes: bytes) -> bytes:
106
- from PIL import Image
107
- import torch
108
-
109
- # Hardcoded parameters that were previously passed from the UI
110
- prompt = "isometric 3d minecraft block voxel style, high resolution, volumetric lighting"
111
- strength = 0.45
112
-
113
- input_image = Image.open(io.BytesIO(img_bytes)).convert("RGB")
114
- input_image = input_image.resize((512, 512))
115
-
116
- with torch.inference_mode():
117
- output_image = self.pipe(
118
- prompt=prompt,
119
- image=input_image,
120
- strength=strength,
121
- num_inference_steps=4,
122
- guidance_scale=3.5,
123
- ).images[0]
124
-
125
- output_buffer = io.BytesIO()
126
- output_image.save(output_buffer, format="JPEG", quality=85)
127
- return output_buffer.getvalue()