Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,6 +38,8 @@ def initialize_models(device):
|
|
| 38 |
g.trellis_pipeline = TrellisImageTo3DPipeline.from_pretrained(
|
| 39 |
"JeffreyXiang/TRELLIS-image-large"
|
| 40 |
)
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# 이미지 생성 파이프라인
|
| 43 |
g.flux_pipe = FluxPipeline.from_pretrained(
|
|
@@ -59,7 +61,7 @@ def initialize_models(device):
|
|
| 59 |
g.translator = transformers_pipeline(
|
| 60 |
"translation",
|
| 61 |
model="Helsinki-NLP/opus-mt-ko-en",
|
| 62 |
-
device=device
|
| 63 |
)
|
| 64 |
|
| 65 |
# CUDA 메모리 관리 설정
|
|
@@ -171,32 +173,49 @@ def unpack_state(state: dict) -> Tuple[Gaussian, edict, str]:
|
|
| 171 |
|
| 172 |
@spaces.GPU
|
| 173 |
def image_to_3d(trial_id: str, seed: int, randomize_seed: bool, ss_guidance_strength: float, ss_sampling_steps: int, slat_guidance_strength: float, slat_sampling_steps: int) -> Tuple[dict, str]:
|
| 174 |
-
if
|
| 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 |
@spaces.GPU
|
|
|
|
| 38 |
g.trellis_pipeline = TrellisImageTo3DPipeline.from_pretrained(
|
| 39 |
"JeffreyXiang/TRELLIS-image-large"
|
| 40 |
)
|
| 41 |
+
if torch.cuda.is_available():
|
| 42 |
+
g.trellis_pipeline = g.trellis_pipeline.to("cuda")
|
| 43 |
|
| 44 |
# 이미지 생성 파이프라인
|
| 45 |
g.flux_pipe = FluxPipeline.from_pretrained(
|
|
|
|
| 61 |
g.translator = transformers_pipeline(
|
| 62 |
"translation",
|
| 63 |
model="Helsinki-NLP/opus-mt-ko-en",
|
| 64 |
+
device=device if device != "cuda" else 0
|
| 65 |
)
|
| 66 |
|
| 67 |
# CUDA 메모리 관리 설정
|
|
|
|
| 173 |
|
| 174 |
@spaces.GPU
|
| 175 |
def image_to_3d(trial_id: str, seed: int, randomize_seed: bool, ss_guidance_strength: float, ss_sampling_steps: int, slat_guidance_strength: float, slat_sampling_steps: int) -> Tuple[dict, str]:
|
| 176 |
+
if not trial_id: # trial_id 검증 추가
|
| 177 |
+
print("Error: No trial_id provided")
|
| 178 |
+
return None, None
|
| 179 |
+
|
| 180 |
+
try:
|
| 181 |
+
if randomize_seed:
|
| 182 |
+
seed = np.random.randint(0, MAX_SEED)
|
| 183 |
+
|
| 184 |
+
image_path = f"{TMP_DIR}/{trial_id}.png"
|
| 185 |
+
if not os.path.exists(image_path):
|
| 186 |
+
print(f"Error: Image file not found at {image_path}")
|
| 187 |
+
return None, None
|
| 188 |
+
|
| 189 |
+
image = Image.open(image_path)
|
| 190 |
+
|
| 191 |
+
outputs = g.trellis_pipeline.run(
|
| 192 |
+
image,
|
| 193 |
+
seed=seed,
|
| 194 |
+
formats=["gaussian", "mesh"],
|
| 195 |
+
preprocess_image=False,
|
| 196 |
+
sparse_structure_sampler_params={
|
| 197 |
+
"steps": ss_sampling_steps,
|
| 198 |
+
"cfg_strength": ss_guidance_strength,
|
| 199 |
+
},
|
| 200 |
+
slat_sampler_params={
|
| 201 |
+
"steps": slat_sampling_steps,
|
| 202 |
+
"cfg_strength": slat_guidance_strength,
|
| 203 |
+
},
|
| 204 |
+
)
|
| 205 |
|
| 206 |
+
video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
|
| 207 |
+
video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
|
| 208 |
+
video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
|
| 209 |
+
new_trial_id = str(uuid.uuid4())
|
| 210 |
+
video_path = f"{TMP_DIR}/{new_trial_id}.mp4"
|
| 211 |
+
os.makedirs(os.path.dirname(video_path), exist_ok=True)
|
| 212 |
+
imageio.mimsave(video_path, video, fps=15)
|
| 213 |
+
state = pack_state(outputs['gaussian'][0], outputs['mesh'][0], new_trial_id)
|
| 214 |
+
return state, video_path
|
| 215 |
+
|
| 216 |
+
except Exception as e:
|
| 217 |
+
print(f"Error in image_to_3d: {str(e)}")
|
| 218 |
+
return None, None
|
| 219 |
|
| 220 |
|
| 221 |
@spaces.GPU
|