aiqtech commited on
Commit
61b9b71
·
verified ·
1 Parent(s): dfb97d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -35
app.py CHANGED
@@ -210,43 +210,37 @@ def image_to_3d(trial_id: str, seed: int, randomize_seed: bool, ss_guidance_stre
210
  image = Image.open(image_path)
211
  print(f"Successfully loaded image with size: {image.size}")
212
 
213
- # GPU로 모델 이동
214
- if not g.trellis_pipeline.device.type == "cuda":
215
- g.trellis_pipeline = g.trellis_pipeline.to("cuda")
216
-
217
- outputs = g.trellis_pipeline.run(
218
- image,
219
- seed=seed,
220
- formats=["gaussian", "mesh"],
221
- preprocess_image=False,
222
- sparse_structure_sampler_params={
223
- "steps": ss_sampling_steps,
224
- "cfg_strength": ss_guidance_strength,
225
- },
226
- slat_sampler_params={
227
- "steps": slat_sampling_steps,
228
- "cfg_strength": slat_guidance_strength,
229
- },
230
- )
231
 
232
- video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
233
- video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
234
- video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
235
- new_trial_id = str(uuid.uuid4())
236
- video_path = f"{TMP_DIR}/{new_trial_id}.mp4"
237
- os.makedirs(os.path.dirname(video_path), exist_ok=True)
238
- imageio.mimsave(video_path, video, fps=15)
239
- state = pack_state(outputs['gaussian'][0], outputs['mesh'][0], new_trial_id)
240
-
241
- # CPU로 모델 되돌리기
242
- g.trellis_pipeline = g.trellis_pipeline.to("cpu")
243
-
244
- return state, video_path
245
 
246
  except Exception as e:
247
  print(f"Error in image_to_3d: {str(e)}")
248
- if g.trellis_pipeline.device.type == "cuda":
249
- g.trellis_pipeline = g.trellis_pipeline.to("cpu")
250
  return None, None
251
 
252
 
@@ -498,8 +492,7 @@ if __name__ == "__main__":
498
  allowed_paths=[PERSISTENT_DIR, TMP_DIR],
499
  server_name="0.0.0.0",
500
  server_port=7860,
501
- show_error=True,
502
- share=True
503
  )
504
 
505
  except Exception as e:
 
210
  image = Image.open(image_path)
211
  print(f"Successfully loaded image with size: {image.size}")
212
 
213
+ with torch.cuda.device(0):
214
+ outputs = g.trellis_pipeline.run(
215
+ image,
216
+ seed=seed,
217
+ formats=["gaussian", "mesh"],
218
+ preprocess_image=False,
219
+ sparse_structure_sampler_params={
220
+ "steps": ss_sampling_steps,
221
+ "cfg_strength": ss_guidance_strength,
222
+ },
223
+ slat_sampler_params={
224
+ "steps": slat_sampling_steps,
225
+ "cfg_strength": slat_guidance_strength,
226
+ },
227
+ )
 
 
 
228
 
229
+ video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
230
+ video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
231
+ video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
232
+ new_trial_id = str(uuid.uuid4())
233
+ video_path = f"{TMP_DIR}/{new_trial_id}.mp4"
234
+ os.makedirs(os.path.dirname(video_path), exist_ok=True)
235
+ imageio.mimsave(video_path, video, fps=15)
236
+ state = pack_state(outputs['gaussian'][0], outputs['mesh'][0], new_trial_id)
237
+
238
+ torch.cuda.empty_cache()
239
+ return state, video_path
 
 
240
 
241
  except Exception as e:
242
  print(f"Error in image_to_3d: {str(e)}")
243
+ torch.cuda.empty_cache()
 
244
  return None, None
245
 
246
 
 
492
  allowed_paths=[PERSISTENT_DIR, TMP_DIR],
493
  server_name="0.0.0.0",
494
  server_port=7860,
495
+ show_error=True
 
496
  )
497
 
498
  except Exception as e: