geyik2 commited on
Commit
be10af7
·
verified ·
1 Parent(s): 931cc7b

Upload 194 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +64 -0
  2. README.md +16 -0
  3. app.py +329 -0
  4. apt-dependencies.txt +7 -0
  5. assets/example_image/T.png +3 -0
  6. assets/example_image/typical_building_building.png +3 -0
  7. assets/example_image/typical_building_castle.png +3 -0
  8. assets/example_image/typical_building_colorful_cottage.png +3 -0
  9. assets/example_image/typical_building_maya_pyramid.png +3 -0
  10. assets/example_image/typical_building_mushroom.png +3 -0
  11. assets/example_image/typical_building_space_station.png +3 -0
  12. assets/example_image/typical_creature_dragon.png +3 -0
  13. assets/example_image/typical_creature_elephant.png +3 -0
  14. assets/example_image/typical_creature_furry.png +3 -0
  15. assets/example_image/typical_creature_quadruped.png +3 -0
  16. assets/example_image/typical_creature_robot_crab.png +3 -0
  17. assets/example_image/typical_creature_robot_dinosour.png +3 -0
  18. assets/example_image/typical_creature_rock_monster.png +3 -0
  19. assets/example_image/typical_humanoid_block_robot.png +3 -0
  20. assets/example_image/typical_humanoid_dragonborn.png +3 -0
  21. assets/example_image/typical_humanoid_dwarf.png +3 -0
  22. assets/example_image/typical_humanoid_goblin.png +3 -0
  23. assets/example_image/typical_humanoid_mech.png +3 -0
  24. assets/example_image/typical_misc_crate.png +3 -0
  25. assets/example_image/typical_misc_fireplace.png +3 -0
  26. assets/example_image/typical_misc_gate.png +3 -0
  27. assets/example_image/typical_misc_lantern.png +3 -0
  28. assets/example_image/typical_misc_magicbook.png +3 -0
  29. assets/example_image/typical_misc_mailbox.png +3 -0
  30. assets/example_image/typical_misc_monster_chest.png +3 -0
  31. assets/example_image/typical_misc_paper_machine.png +3 -0
  32. assets/example_image/typical_misc_phonograph.png +3 -0
  33. assets/example_image/typical_misc_portal2.png +3 -0
  34. assets/example_image/typical_misc_storage_chest.png +3 -0
  35. assets/example_image/typical_misc_telephone.png +3 -0
  36. assets/example_image/typical_misc_television.png +3 -0
  37. assets/example_image/typical_misc_workbench.png +3 -0
  38. assets/example_image/typical_vehicle_biplane.png +3 -0
  39. assets/example_image/typical_vehicle_bulldozer.png +3 -0
  40. assets/example_image/typical_vehicle_cart.png +3 -0
  41. assets/example_image/typical_vehicle_excavator.png +3 -0
  42. assets/example_image/typical_vehicle_helicopter.png +3 -0
  43. assets/example_image/typical_vehicle_locomotive.png +3 -0
  44. assets/example_image/typical_vehicle_pirate_ship.png +3 -0
  45. assets/example_image/weatherworn_misc_paper_machine3.png +3 -0
  46. assets/example_multi_image/character_1.png +3 -0
  47. assets/example_multi_image/character_2.png +3 -0
  48. assets/example_multi_image/character_3.png +3 -0
  49. assets/example_multi_image/mushroom_1.png +3 -0
  50. assets/example_multi_image/mushroom_2.png +3 -0
.gitattributes ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ assets/example_image/T.png filter=lfs diff=lfs merge=lfs -text
2
+ assets/example_image/typical_building_building.png filter=lfs diff=lfs merge=lfs -text
3
+ assets/example_image/typical_building_castle.png filter=lfs diff=lfs merge=lfs -text
4
+ assets/example_image/typical_building_colorful_cottage.png filter=lfs diff=lfs merge=lfs -text
5
+ assets/example_image/typical_building_maya_pyramid.png filter=lfs diff=lfs merge=lfs -text
6
+ assets/example_image/typical_building_mushroom.png filter=lfs diff=lfs merge=lfs -text
7
+ assets/example_image/typical_building_space_station.png filter=lfs diff=lfs merge=lfs -text
8
+ assets/example_image/typical_creature_dragon.png filter=lfs diff=lfs merge=lfs -text
9
+ assets/example_image/typical_creature_elephant.png filter=lfs diff=lfs merge=lfs -text
10
+ assets/example_image/typical_creature_furry.png filter=lfs diff=lfs merge=lfs -text
11
+ assets/example_image/typical_creature_quadruped.png filter=lfs diff=lfs merge=lfs -text
12
+ assets/example_image/typical_creature_robot_crab.png filter=lfs diff=lfs merge=lfs -text
13
+ assets/example_image/typical_creature_robot_dinosour.png filter=lfs diff=lfs merge=lfs -text
14
+ assets/example_image/typical_creature_rock_monster.png filter=lfs diff=lfs merge=lfs -text
15
+ assets/example_image/typical_humanoid_block_robot.png filter=lfs diff=lfs merge=lfs -text
16
+ assets/example_image/typical_humanoid_dragonborn.png filter=lfs diff=lfs merge=lfs -text
17
+ assets/example_image/typical_humanoid_dwarf.png filter=lfs diff=lfs merge=lfs -text
18
+ assets/example_image/typical_humanoid_goblin.png filter=lfs diff=lfs merge=lfs -text
19
+ assets/example_image/typical_humanoid_mech.png filter=lfs diff=lfs merge=lfs -text
20
+ assets/example_image/typical_misc_crate.png filter=lfs diff=lfs merge=lfs -text
21
+ assets/example_image/typical_misc_fireplace.png filter=lfs diff=lfs merge=lfs -text
22
+ assets/example_image/typical_misc_gate.png filter=lfs diff=lfs merge=lfs -text
23
+ assets/example_image/typical_misc_lantern.png filter=lfs diff=lfs merge=lfs -text
24
+ assets/example_image/typical_misc_magicbook.png filter=lfs diff=lfs merge=lfs -text
25
+ assets/example_image/typical_misc_mailbox.png filter=lfs diff=lfs merge=lfs -text
26
+ assets/example_image/typical_misc_monster_chest.png filter=lfs diff=lfs merge=lfs -text
27
+ assets/example_image/typical_misc_paper_machine.png filter=lfs diff=lfs merge=lfs -text
28
+ assets/example_image/typical_misc_phonograph.png filter=lfs diff=lfs merge=lfs -text
29
+ assets/example_image/typical_misc_portal2.png filter=lfs diff=lfs merge=lfs -text
30
+ assets/example_image/typical_misc_storage_chest.png filter=lfs diff=lfs merge=lfs -text
31
+ assets/example_image/typical_misc_telephone.png filter=lfs diff=lfs merge=lfs -text
32
+ assets/example_image/typical_misc_television.png filter=lfs diff=lfs merge=lfs -text
33
+ assets/example_image/typical_misc_workbench.png filter=lfs diff=lfs merge=lfs -text
34
+ assets/example_image/typical_vehicle_biplane.png filter=lfs diff=lfs merge=lfs -text
35
+ assets/example_image/typical_vehicle_bulldozer.png filter=lfs diff=lfs merge=lfs -text
36
+ assets/example_image/typical_vehicle_cart.png filter=lfs diff=lfs merge=lfs -text
37
+ assets/example_image/typical_vehicle_excavator.png filter=lfs diff=lfs merge=lfs -text
38
+ assets/example_image/typical_vehicle_helicopter.png filter=lfs diff=lfs merge=lfs -text
39
+ assets/example_image/typical_vehicle_locomotive.png filter=lfs diff=lfs merge=lfs -text
40
+ assets/example_image/typical_vehicle_pirate_ship.png filter=lfs diff=lfs merge=lfs -text
41
+ assets/example_image/weatherworn_misc_paper_machine3.png filter=lfs diff=lfs merge=lfs -text
42
+ assets/example_multi_image/character_1.png filter=lfs diff=lfs merge=lfs -text
43
+ assets/example_multi_image/character_2.png filter=lfs diff=lfs merge=lfs -text
44
+ assets/example_multi_image/character_3.png filter=lfs diff=lfs merge=lfs -text
45
+ assets/example_multi_image/mushroom_1.png filter=lfs diff=lfs merge=lfs -text
46
+ assets/example_multi_image/mushroom_2.png filter=lfs diff=lfs merge=lfs -text
47
+ assets/example_multi_image/mushroom_3.png filter=lfs diff=lfs merge=lfs -text
48
+ assets/example_multi_image/orangeguy_1.png filter=lfs diff=lfs merge=lfs -text
49
+ assets/example_multi_image/orangeguy_2.png filter=lfs diff=lfs merge=lfs -text
50
+ assets/example_multi_image/orangeguy_3.png filter=lfs diff=lfs merge=lfs -text
51
+ assets/example_multi_image/popmart_1.png filter=lfs diff=lfs merge=lfs -text
52
+ assets/example_multi_image/popmart_2.png filter=lfs diff=lfs merge=lfs -text
53
+ assets/example_multi_image/popmart_3.png filter=lfs diff=lfs merge=lfs -text
54
+ assets/example_multi_image/rabbit_1.png filter=lfs diff=lfs merge=lfs -text
55
+ assets/example_multi_image/rabbit_2.png filter=lfs diff=lfs merge=lfs -text
56
+ assets/example_multi_image/rabbit_3.png filter=lfs diff=lfs merge=lfs -text
57
+ assets/example_multi_image/tiger_1.png filter=lfs diff=lfs merge=lfs -text
58
+ assets/example_multi_image/tiger_2.png filter=lfs diff=lfs merge=lfs -text
59
+ assets/example_multi_image/tiger_3.png filter=lfs diff=lfs merge=lfs -text
60
+ assets/example_multi_image/yoimiya_1.png filter=lfs diff=lfs merge=lfs -text
61
+ assets/example_multi_image/yoimiya_2.png filter=lfs diff=lfs merge=lfs -text
62
+ assets/example_multi_image/yoimiya_3.png filter=lfs diff=lfs merge=lfs -text
63
+ wheels/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl filter=lfs diff=lfs merge=lfs -text
64
+ wheels/nvdiffrast-0.3.3-cp310-cp310-linux_x86_64.whl filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: FLUX TRELLIS
3
+ emoji: 🏢
4
+ colorFrom: indigo
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 4.44.1
8
+ app_file: app.py
9
+ pinned: true
10
+ license: mit
11
+ short_description: 3D Generation from text prompts
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
15
+
16
+ Paper: https://huggingface.co/papers/2412.01506
app.py ADDED
@@ -0,0 +1,329 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import spaces
3
+ from gradio_litmodel3d import LitModel3D
4
+ import os
5
+ import shutil
6
+ import random
7
+ import uuid
8
+ from datetime import datetime
9
+ from diffusers import DiffusionPipeline
10
+
11
+ os.environ['SPCONV_ALGO'] = 'native'
12
+ from typing import *
13
+ import torch
14
+ import numpy as np
15
+ import imageio
16
+ from easydict import EasyDict as edict
17
+ from PIL import Image
18
+ from trellis.pipelines import TrellisImageTo3DPipeline
19
+ from trellis.representations import Gaussian, MeshExtractResult
20
+ from trellis.utils import render_utils, postprocessing_utils
21
+
22
+ NUM_INFERENCE_STEPS = 8
23
+
24
+ huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
25
+ # Constants
26
+ MAX_SEED = np.iinfo(np.int32).max
27
+ TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
28
+ os.makedirs(TMP_DIR, exist_ok=True)
29
+
30
+ # Create permanent storage directory for Flux generated images
31
+ SAVE_DIR = "saved_images"
32
+ if not os.path.exists(SAVE_DIR):
33
+ os.makedirs(SAVE_DIR, exist_ok=True)
34
+
35
+ # Initialize device
36
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
37
+
38
+ # Initialize Flux pipeline
39
+ flux_pipeline = DiffusionPipeline.from_pretrained(
40
+ "black-forest-labs/FLUX.1-dev",
41
+ torch_dtype=torch.float16,
42
+ variant="fp16",
43
+ use_safetensors=True,
44
+ local_files_only=False
45
+ ).to(device)
46
+
47
+ # Initialize TRELLIS pipeline
48
+ trellis_pipeline = TrellisImageTo3DPipeline.from_pretrained(
49
+ "JeffreyXiang/TRELLIS-image-large",
50
+ torch_dtype=torch.float16,
51
+ variant="fp16",
52
+ use_safetensors=True,
53
+ local_files_only=False
54
+ ).to(device)
55
+
56
+ def start_session(req: gr.Request):
57
+ user_dir = os.path.join(TMP_DIR, str(req.session_hash))
58
+ os.makedirs(user_dir, exist_ok=True)
59
+
60
+ def end_session(req: gr.Request):
61
+ user_dir = os.path.join(TMP_DIR, str(req.session_hash))
62
+ shutil.rmtree(user_dir)
63
+
64
+ def preprocess_image(image: Image.Image) -> Image.Image:
65
+ processed_image = trellis_pipeline.preprocess_image(image)
66
+ return processed_image
67
+
68
+ def pack_state(gs: Gaussian, mesh: MeshExtractResult) -> dict:
69
+ return {
70
+ 'gaussian': {
71
+ **gs.init_params,
72
+ '_xyz': gs._xyz.cpu().numpy(),
73
+ '_features_dc': gs._features_dc.cpu().numpy(),
74
+ '_scaling': gs._scaling.cpu().numpy(),
75
+ '_rotation': gs._rotation.cpu().numpy(),
76
+ '_opacity': gs._opacity.cpu().numpy(),
77
+ },
78
+ 'mesh': {
79
+ 'vertices': mesh.vertices.cpu().numpy(),
80
+ 'faces': mesh.faces.cpu().numpy(),
81
+ },
82
+ }
83
+
84
+ def unpack_state(state: dict) -> Tuple[Gaussian, edict]:
85
+ gs = Gaussian(
86
+ aabb=state['gaussian']['aabb'],
87
+ sh_degree=state['gaussian']['sh_degree'],
88
+ mininum_kernel_size=state['gaussian']['mininum_kernel_size'],
89
+ scaling_bias=state['gaussian']['scaling_bias'],
90
+ opacity_bias=state['gaussian']['opacity_bias'],
91
+ scaling_activation=state['gaussian']['scaling_activation'],
92
+ )
93
+ gs._xyz = torch.tensor(state['gaussian']['_xyz'], device='cuda')
94
+ gs._features_dc = torch.tensor(state['gaussian']['_features_dc'], device='cuda')
95
+ gs._scaling = torch.tensor(state['gaussian']['_scaling'], device='cuda')
96
+ gs._rotation = torch.tensor(state['gaussian']['_rotation'], device='cuda')
97
+ gs._opacity = torch.tensor(state['gaussian']['_opacity'], device='cuda')
98
+
99
+ mesh = edict(
100
+ vertices=torch.tensor(state['mesh']['vertices'], device='cuda'),
101
+ faces=torch.tensor(state['mesh']['faces'], device='cuda'),
102
+ )
103
+
104
+ return gs, mesh
105
+
106
+ def get_seed(randomize_seed: bool, seed: int) -> int:
107
+ return np.random.randint(0, MAX_SEED) if randomize_seed else seed
108
+
109
+ @spaces.GPU
110
+ def generate_flux_image(
111
+ prompt: str,
112
+ seed: int,
113
+ randomize_seed: bool,
114
+ width: int,
115
+ height: int,
116
+ guidance_scale: float,
117
+ progress: gr.Progress = gr.Progress(track_tqdm=True),
118
+ ) -> Image.Image:
119
+ """Generate image using Flux pipeline"""
120
+ if randomize_seed:
121
+ seed = random.randint(0, MAX_SEED)
122
+ generator = torch.Generator(device=device).manual_seed(seed)
123
+ prompt = "wbgmsst, " + prompt + ", 3D isometric, white background"
124
+ image = flux_pipeline(
125
+ prompt=prompt,
126
+ guidance_scale=guidance_scale,
127
+ num_inference_steps=NUM_INFERENCE_STEPS,
128
+ width=width,
129
+ height=height,
130
+ generator=generator,
131
+ ).images[0]
132
+
133
+ # Save the generated image
134
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
135
+ unique_id = str(uuid.uuid4())[:8]
136
+ filename = f"{timestamp}_{unique_id}.png"
137
+ filepath = os.path.join(SAVE_DIR, filename)
138
+ image.save(filepath)
139
+
140
+ return image
141
+
142
+ @spaces.GPU
143
+ def image_to_3d(
144
+ image: Image.Image,
145
+ seed: int,
146
+ ss_guidance_strength: float,
147
+ ss_sampling_steps: int,
148
+ slat_guidance_strength: float,
149
+ slat_sampling_steps: int,
150
+ req: gr.Request,
151
+ ) -> Tuple[dict, str]:
152
+ user_dir = os.path.join(TMP_DIR, str(req.session_hash))
153
+ outputs = trellis_pipeline.run(
154
+ image,
155
+ seed=seed,
156
+ formats=["gaussian", "mesh"],
157
+ preprocess_image=False,
158
+ sparse_structure_sampler_params={
159
+ "steps": ss_sampling_steps,
160
+ "cfg_strength": ss_guidance_strength,
161
+ },
162
+ slat_sampler_params={
163
+ "steps": slat_sampling_steps,
164
+ "cfg_strength": slat_guidance_strength,
165
+ },
166
+ )
167
+ video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
168
+ video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
169
+ video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
170
+ video_path = os.path.join(user_dir, 'sample.mp4')
171
+ imageio.mimsave(video_path, video, fps=15)
172
+ state = pack_state(outputs['gaussian'][0], outputs['mesh'][0])
173
+ torch.cuda.empty_cache()
174
+ return state, video_path
175
+
176
+ @spaces.GPU(duration=90)
177
+ def extract_glb(
178
+ state: dict,
179
+ mesh_simplify: float,
180
+ texture_size: int,
181
+ req: gr.Request,
182
+ ) -> Tuple[str, str]:
183
+ user_dir = os.path.join(TMP_DIR, str(req.session_hash))
184
+ gs, mesh = unpack_state(state)
185
+ glb = postprocessing_utils.to_glb(gs, mesh, simplify=mesh_simplify, texture_size=texture_size, verbose=False)
186
+ glb_path = os.path.join(user_dir, 'sample.glb')
187
+ glb.export(glb_path)
188
+ torch.cuda.empty_cache()
189
+ return glb_path, glb_path
190
+
191
+ @spaces.GPU
192
+ def extract_gaussian(state: dict, req: gr.Request) -> Tuple[str, str]:
193
+ user_dir = os.path.join(TMP_DIR, str(req.session_hash))
194
+ gs, _ = unpack_state(state)
195
+ gaussian_path = os.path.join(user_dir, 'sample.ply')
196
+ gs.save_ply(gaussian_path)
197
+ torch.cuda.empty_cache()
198
+ return gaussian_path, gaussian_path
199
+
200
+ # Gradio Interface
201
+ with gr.Blocks() as demo:
202
+ gr.Markdown("""
203
+ ## Game Asset Generation to 3D with FLUX and TRELLIS
204
+ * Enter a prompt to generate a game asset image, then convert it to 3D
205
+ * If you find the generated 3D asset satisfactory, click "Extract GLB" to extract the GLB file and download it.
206
+ * [TRELLIS Model](https://huggingface.co/JeffreyXiang/TRELLIS-image-large) [Trellis Github](https://github.com/microsoft/TRELLIS) [Flux-Dev](https://huggingface.co/black-forest-labs/FLUX.1-dev)
207
+ * [Flux Game Assets LoRA](https://huggingface.co/gokaygokay/Flux-Game-Assets-LoRA-v2) [Hyper FLUX 8Steps LoRA](https://huggingface.co/ByteDance/Hyper-SD) [safetensors to GGUF for Flux](https://github.com/ruSauron/to-gguf-bat) [Thanks to John6666](https://huggingface.co/John6666)
208
+ """)
209
+
210
+ with gr.Row():
211
+ with gr.Column():
212
+ # Flux image generation inputs
213
+ prompt = gr.Text(label="Prompt", placeholder="Enter your game asset description")
214
+
215
+ with gr.Accordion("Generation Settings", open=False):
216
+ seed = gr.Slider(0, MAX_SEED, label="Seed", value=42, step=1)
217
+ randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
218
+ with gr.Row():
219
+ width = gr.Slider(512, 1024, label="Width", value=1024, step=16)
220
+ height = gr.Slider(512, 1024, label="Height", value=1024, step=16)
221
+ with gr.Row():
222
+ guidance_scale = gr.Slider(0.0, 10.0, label="Guidance Scale", value=3.5, step=0.1)
223
+ # num_inference_steps = gr.Slider(1, 50, label="Steps", value=8, step=1)
224
+
225
+ with gr.Accordion("3D Generation Settings", open=False):
226
+ gr.Markdown("Stage 1: Sparse Structure Generation")
227
+ with gr.Row():
228
+ ss_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=7.5, step=0.1)
229
+ ss_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
230
+ gr.Markdown("Stage 2: Structured Latent Generation")
231
+ with gr.Row():
232
+ slat_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=3.0, step=0.1)
233
+ slat_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
234
+
235
+ generate_btn = gr.Button("Generate")
236
+
237
+ with gr.Accordion("GLB Extraction Settings", open=False):
238
+ mesh_simplify = gr.Slider(0.9, 0.98, label="Simplify", value=0.95, step=0.01)
239
+ texture_size = gr.Slider(512, 2048, label="Texture Size", value=1024, step=512)
240
+
241
+ with gr.Row():
242
+ extract_glb_btn = gr.Button("Extract GLB", interactive=False)
243
+ extract_gs_btn = gr.Button("Extract Gaussian", interactive=False)
244
+
245
+ with gr.Column():
246
+ generated_image = gr.Image(label="Generated Asset", type="pil")
247
+
248
+ with gr.Column():
249
+
250
+ video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True)
251
+ model_output = LitModel3D(label="Extracted GLB/Gaussian", exposure=8.0, height=400)
252
+
253
+ with gr.Row():
254
+ download_glb = gr.DownloadButton(label="Download GLB", interactive=False)
255
+ download_gs = gr.DownloadButton(label="Download Gaussian", interactive=False)
256
+
257
+ output_buf = gr.State()
258
+
259
+ # Event handlers
260
+ demo.load(start_session)
261
+ demo.unload(end_session)
262
+
263
+ generate_btn.click(
264
+ generate_flux_image,
265
+ inputs=[prompt, seed, randomize_seed, width, height, guidance_scale],
266
+ outputs=[generated_image],
267
+ ).then(
268
+ image_to_3d,
269
+ inputs=[generated_image, seed, ss_guidance_strength, ss_sampling_steps, slat_guidance_strength, slat_sampling_steps],
270
+ outputs=[output_buf, video_output],
271
+ ).then(
272
+ lambda: (True, True),
273
+ outputs=[extract_glb_btn, extract_gs_btn]
274
+ )
275
+
276
+ extract_glb_btn.click(
277
+ extract_glb,
278
+ inputs=[output_buf, mesh_simplify, texture_size],
279
+ outputs=[model_output, download_glb]
280
+ ).then(
281
+ lambda: True,
282
+ outputs=[download_glb]
283
+ )
284
+
285
+ extract_gs_btn.click(
286
+ extract_gaussian,
287
+ inputs=[output_buf],
288
+ outputs=[model_output, download_gs]
289
+ ).then(
290
+ lambda: True,
291
+ outputs=[download_gs]
292
+ )
293
+
294
+ model_output.clear(
295
+ lambda: gr.Button(interactive=False),
296
+ outputs=[download_glb],
297
+ )
298
+
299
+ # Initialize both pipelines
300
+ if __name__ == "__main__":
301
+ from diffusers import FluxTransformer2DModel, FluxPipeline, BitsAndBytesConfig, GGUFQuantizationConfig
302
+ from transformers import T5EncoderModel, BitsAndBytesConfig as BitsAndBytesConfigTF
303
+
304
+ # Initialize Flux pipeline
305
+ device = "cuda" if torch.cuda.is_available() else "cpu"
306
+ huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
307
+
308
+ dtype = torch.bfloat16
309
+ file_url = "https://huggingface.co/gokaygokay/flux-game/blob/main/hyperflux_00001_.q8_0.gguf"
310
+ file_url = file_url.replace("/resolve/main/", "/blob/main/").replace("?download=true", "")
311
+ single_file_base_model = "camenduru/FLUX.1-dev-diffusers"
312
+ quantization_config_tf = BitsAndBytesConfigTF(load_in_8bit=True, bnb_8bit_compute_dtype=torch.bfloat16)
313
+ text_encoder_2 = T5EncoderModel.from_pretrained(single_file_base_model, subfolder="text_encoder_2", torch_dtype=dtype, config=single_file_base_model, quantization_config=quantization_config_tf, token=huggingface_token)
314
+ if ".gguf" in file_url:
315
+ transformer = FluxTransformer2DModel.from_single_file(file_url, subfolder="transformer", quantization_config=GGUFQuantizationConfig(compute_dtype=dtype), torch_dtype=dtype, config=single_file_base_model)
316
+ else:
317
+ quantization_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_use_double_quant=True, bnb_4bit_compute_dtype=torch.bfloat16, token=huggingface_token)
318
+ transformer = FluxTransformer2DModel.from_single_file(file_url, subfolder="transformer", torch_dtype=dtype, config=single_file_base_model, quantization_config=quantization_config, token=huggingface_token)
319
+ flux_pipeline = FluxPipeline.from_pretrained(single_file_base_model, transformer=transformer, text_encoder_2=text_encoder_2, torch_dtype=dtype, token=huggingface_token)
320
+ flux_pipeline.to("cuda")
321
+ # Initialize Trellis pipeline
322
+ trellis_pipeline = TrellisImageTo3DPipeline.from_pretrained("JeffreyXiang/TRELLIS-image-large")
323
+ trellis_pipeline.cuda()
324
+ try:
325
+ trellis_pipeline.preprocess_image(Image.fromarray(np.zeros((512, 512, 3), dtype=np.uint8)))
326
+ except:
327
+ pass
328
+
329
+ demo.queue(max_size=10).launch()
apt-dependencies.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ cuda-cudart-12-0
2
+ cuda-cudart-dev-12-0
3
+ cuda-nvrtc-12-0
4
+ cuda-nvrtc-dev-12-0
5
+ cuda-runtime-12-0
6
+ libcudart12
7
+ nvidia-cuda-toolkit
assets/example_image/T.png ADDED

Git LFS Details

  • SHA256: e29ddc83a5bd3a05fe9b34732169bc4ea7131f7c36527fdc5f626a90a73076d2
  • Pointer size: 131 Bytes
  • Size of remote file: 955 kB
assets/example_image/typical_building_building.png ADDED

Git LFS Details

  • SHA256: 8faa11d557be95c000c475247e61a773d511114c7d1e517c04f8d3d88a6049ec
  • Pointer size: 131 Bytes
  • Size of remote file: 547 kB
assets/example_image/typical_building_castle.png ADDED

Git LFS Details

  • SHA256: 076f0554b087b921863643d2b1ab3e0572a13a347fd66bc29cd9d194034affae
  • Pointer size: 131 Bytes
  • Size of remote file: 426 kB
assets/example_image/typical_building_colorful_cottage.png ADDED

Git LFS Details

  • SHA256: 687305b4e35da759692be0de614d728583a2a9cd2fd3a55593fa753e567d0d47
  • Pointer size: 131 Bytes
  • Size of remote file: 609 kB
assets/example_image/typical_building_maya_pyramid.png ADDED

Git LFS Details

  • SHA256: 4d514f7f4db244ee184af4ddfbc5948d417b4e5bf1c6ee5f5a592679561690df
  • Pointer size: 131 Bytes
  • Size of remote file: 232 kB
assets/example_image/typical_building_mushroom.png ADDED

Git LFS Details

  • SHA256: de9b72d3e13e967e70844ddc54643832a84a1b35ca043a11e7c774371d0ccdab
  • Pointer size: 131 Bytes
  • Size of remote file: 488 kB
assets/example_image/typical_building_space_station.png ADDED

Git LFS Details

  • SHA256: 212c7b4c27ba1e01a7908dbc7f245e7115850eadbc9974aa726327cf35062846
  • Pointer size: 131 Bytes
  • Size of remote file: 620 kB
assets/example_image/typical_creature_dragon.png ADDED

Git LFS Details

  • SHA256: 0e8d6720dfa1e7b332b76e897e617b7f0863187f30879451b4724f482c84185a
  • Pointer size: 131 Bytes
  • Size of remote file: 564 kB
assets/example_image/typical_creature_elephant.png ADDED

Git LFS Details

  • SHA256: 86a171e37a3d781e7215977f565cd63e813341c1f89e2c586fa61937e4ed6916
  • Pointer size: 131 Bytes
  • Size of remote file: 482 kB
assets/example_image/typical_creature_furry.png ADDED

Git LFS Details

  • SHA256: 5b5445b8f1996cf6d72497b2d7564c656f4048e6c1fa626fd7bb3ee582fee671
  • Pointer size: 131 Bytes
  • Size of remote file: 648 kB
assets/example_image/typical_creature_quadruped.png ADDED

Git LFS Details

  • SHA256: 7469f43f58389adec101e9685f60188bd4e7fbede77eef975102f6a8865bc786
  • Pointer size: 131 Bytes
  • Size of remote file: 685 kB
assets/example_image/typical_creature_robot_crab.png ADDED

Git LFS Details

  • SHA256: d7e716abe8f8895080f562d1dc26b14fa0e20a05aa5beb2770c6fb3b87b3476a
  • Pointer size: 131 Bytes
  • Size of remote file: 594 kB
assets/example_image/typical_creature_robot_dinosour.png ADDED

Git LFS Details

  • SHA256: d0986f29557a6fddf9b52b5251a6b6103728c61e201b1cfad1e709b090b72f56
  • Pointer size: 131 Bytes
  • Size of remote file: 632 kB
assets/example_image/typical_creature_rock_monster.png ADDED

Git LFS Details

  • SHA256: e29458a6110bee8374c0d4d12471e7167a6c1c98c18f6e2d7ff4f5f0ca3fa01b
  • Pointer size: 131 Bytes
  • Size of remote file: 648 kB
assets/example_image/typical_humanoid_block_robot.png ADDED

Git LFS Details

  • SHA256: 3a0acbb532668e1bf35f3eef5bcbfdd094c22219ef2d837fa01ccf51cce75ca3
  • Pointer size: 131 Bytes
  • Size of remote file: 441 kB
assets/example_image/typical_humanoid_dragonborn.png ADDED

Git LFS Details

  • SHA256: 5d7c547909a6c12da55dbab1c1c98181ff09e58c9ba943682ca105e71be9548e
  • Pointer size: 131 Bytes
  • Size of remote file: 481 kB
assets/example_image/typical_humanoid_dwarf.png ADDED

Git LFS Details

  • SHA256: a4a7c157d5d8071128c27594e45a7a03e5113b3333b7f1c5ff1379481e3e0264
  • Pointer size: 131 Bytes
  • Size of remote file: 498 kB
assets/example_image/typical_humanoid_goblin.png ADDED

Git LFS Details

  • SHA256: 2b0e9a04ae3e7bef44b7180a70306f95374b60727ffa0f6f01fd6c746595cd77
  • Pointer size: 131 Bytes
  • Size of remote file: 496 kB
assets/example_image/typical_humanoid_mech.png ADDED

Git LFS Details

  • SHA256: a244ec54b7984e646e54d433de6897657081dd5b9cd5ccd3d865328d813beb49
  • Pointer size: 131 Bytes
  • Size of remote file: 850 kB
assets/example_image/typical_misc_crate.png ADDED

Git LFS Details

  • SHA256: 59fd9884301faca93265166d90078e8c31e76c7f93524b1db31975df4b450748
  • Pointer size: 131 Bytes
  • Size of remote file: 642 kB
assets/example_image/typical_misc_fireplace.png ADDED

Git LFS Details

  • SHA256: 2288c034603e289192d63cbc73565107caefd99e81c4b7afa2983c8b13e34440
  • Pointer size: 131 Bytes
  • Size of remote file: 558 kB
assets/example_image/typical_misc_gate.png ADDED

Git LFS Details

  • SHA256: ec8db5389b74fe56b826e3c6d860234541033387350e09268591c46d411cc8e9
  • Pointer size: 131 Bytes
  • Size of remote file: 572 kB
assets/example_image/typical_misc_lantern.png ADDED

Git LFS Details

  • SHA256: e17bd83adf433ebfca17abd220097b2b7f08affc649518bd7822e03797e83d41
  • Pointer size: 131 Bytes
  • Size of remote file: 300 kB
assets/example_image/typical_misc_magicbook.png ADDED

Git LFS Details

  • SHA256: aff9c14589c340e31b61bf82e4506d77d72c511e741260fa1e600cefa4e103e6
  • Pointer size: 131 Bytes
  • Size of remote file: 496 kB
assets/example_image/typical_misc_mailbox.png ADDED

Git LFS Details

  • SHA256: 01e86a5d68edafb7e11d7a86f7e8081f5ed1b02578198a3271554c5fb8fb9fcf
  • Pointer size: 131 Bytes
  • Size of remote file: 631 kB
assets/example_image/typical_misc_monster_chest.png ADDED

Git LFS Details

  • SHA256: c57a598e842225a31b9770bf3bbb9ae86197ec57d0c2883caf8cb5eed4908fbc
  • Pointer size: 131 Bytes
  • Size of remote file: 690 kB
assets/example_image/typical_misc_paper_machine.png ADDED

Git LFS Details

  • SHA256: 2d55400ae5d4df2377258400d800ece75766d5274e80ce07c3b29a4d1fd1fa36
  • Pointer size: 131 Bytes
  • Size of remote file: 614 kB
assets/example_image/typical_misc_phonograph.png ADDED

Git LFS Details

  • SHA256: 14fff9a27ea769d3ca711e9ff55ab3d9385486a5e8b99117f506df326a0a357e
  • Pointer size: 131 Bytes
  • Size of remote file: 517 kB
assets/example_image/typical_misc_portal2.png ADDED

Git LFS Details

  • SHA256: 57aab2bba56bc946523a3fca77ca70651a4ad8c6fbf1b91a1a824418df48faae
  • Pointer size: 131 Bytes
  • Size of remote file: 386 kB
assets/example_image/typical_misc_storage_chest.png ADDED

Git LFS Details

  • SHA256: 0e4ac1c67fdda902ecb709447b8defd949c738954c844c1b8364b8e3f7d9e55a
  • Pointer size: 131 Bytes
  • Size of remote file: 632 kB
assets/example_image/typical_misc_telephone.png ADDED

Git LFS Details

  • SHA256: 00048be46234a2709c12614b04cbad61c6e3c7e63c2a4ef33d999185f5393e36
  • Pointer size: 131 Bytes
  • Size of remote file: 648 kB
assets/example_image/typical_misc_television.png ADDED

Git LFS Details

  • SHA256: 6a1947b737398bf535ec212668a4d78cd38fe84cf9da1ccd6c0c0d838337755e
  • Pointer size: 131 Bytes
  • Size of remote file: 627 kB
assets/example_image/typical_misc_workbench.png ADDED

Git LFS Details

  • SHA256: a6d9ed4d005a5253b8571fd976b0d102e293512d7b5a8ed5e3f7f17c5f4e19da
  • Pointer size: 131 Bytes
  • Size of remote file: 463 kB
assets/example_image/typical_vehicle_biplane.png ADDED

Git LFS Details

  • SHA256: c73e98112eb603b4ba635b8965cad7807d0588f083811bc2faa0c7ab9668a65a
  • Pointer size: 131 Bytes
  • Size of remote file: 574 kB
assets/example_image/typical_vehicle_bulldozer.png ADDED

Git LFS Details

  • SHA256: 23d821b4daea61cbea28cc6ddd3ae46712514dfcdff995c2664f5a70d21f4ef3
  • Pointer size: 131 Bytes
  • Size of remote file: 693 kB
assets/example_image/typical_vehicle_cart.png ADDED

Git LFS Details

  • SHA256: b72c04a2aa5cf57717c05151a2982d6dc31afde130d5e830adf37a84a70616cb
  • Pointer size: 131 Bytes
  • Size of remote file: 693 kB
assets/example_image/typical_vehicle_excavator.png ADDED

Git LFS Details

  • SHA256: 27a418853eefa197f1e10ed944a7bb071413fd2bc1681804ee773a6ce3799c52
  • Pointer size: 131 Bytes
  • Size of remote file: 712 kB
assets/example_image/typical_vehicle_helicopter.png ADDED

Git LFS Details

  • SHA256: 7f1a1b37bc52417c0e1048927a30bf3a52dde81345f90114040608186196ffe7
  • Pointer size: 131 Bytes
  • Size of remote file: 353 kB
assets/example_image/typical_vehicle_locomotive.png ADDED

Git LFS Details

  • SHA256: 67d5124e7069b133dc0aaa16047a52c6dc1d7c2a4e4510ffd3235fe95597fbef
  • Pointer size: 131 Bytes
  • Size of remote file: 806 kB
assets/example_image/typical_vehicle_pirate_ship.png ADDED

Git LFS Details

  • SHA256: 8926ec7c9f36a52e3bf1ca4e8cfc75d297da934fe7c0e8d7a73f0d35a5ef38ad
  • Pointer size: 131 Bytes
  • Size of remote file: 611 kB
assets/example_image/weatherworn_misc_paper_machine3.png ADDED

Git LFS Details

  • SHA256: 3c6fbf47ed53ffad1a3027f72bf0806c238682c7bf7604b8770aef428906d33b
  • Pointer size: 131 Bytes
  • Size of remote file: 502 kB
assets/example_multi_image/character_1.png ADDED

Git LFS Details

  • SHA256: 729e2e0214232e1dd45c9187e339f8a2a87c6e41257ef701e578a4f0a8be7ef1
  • Pointer size: 131 Bytes
  • Size of remote file: 172 kB
assets/example_multi_image/character_2.png ADDED

Git LFS Details

  • SHA256: e8afc8af9960a5f2315d9d5b9815f29137ef9b63c4d512c451a8ba374003c3ac
  • Pointer size: 131 Bytes
  • Size of remote file: 198 kB
assets/example_multi_image/character_3.png ADDED

Git LFS Details

  • SHA256: 3413a2b4f67105b947a42ebbe14d3f6ab9f68a99f2258a86fd50d94342b49bdd
  • Pointer size: 131 Bytes
  • Size of remote file: 146 kB
assets/example_multi_image/mushroom_1.png ADDED

Git LFS Details

  • SHA256: 3e5fd9ee75d39c827b0c5544392c255a89b4ca62bf3cf31f702d39b150bea00c
  • Pointer size: 131 Bytes
  • Size of remote file: 434 kB
assets/example_multi_image/mushroom_2.png ADDED

Git LFS Details

  • SHA256: 6e5709b910341b12d149632b8442aebd218dd591b238ccb7e4e8b185860aae04
  • Pointer size: 131 Bytes
  • Size of remote file: 462 kB