souging commited on
Commit
0ffdd0f
·
verified ·
1 Parent(s): 97f9a6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import gradio as gr
2
- import spaces
3
 
4
  import os
5
  import shutil
@@ -30,7 +29,7 @@ def start_session(req: gr.Request):
30
 
31
  def end_session(req: gr.Request):
32
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
33
- shutil.rmtree(user_dir)
34
 
35
 
36
  def pack_state(gs: Gaussian, mesh: MeshExtractResult) -> dict:
@@ -80,7 +79,6 @@ def get_seed(randomize_seed: bool, seed: int) -> int:
80
  return np.random.randint(0, MAX_SEED) if randomize_seed else seed
81
 
82
 
83
- @spaces.GPU
84
  def text_to_3d(
85
  prompt: str,
86
  seed: int,
@@ -106,6 +104,7 @@ def text_to_3d(
106
  str: The path to the video of the 3D model.
107
  """
108
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
 
109
  outputs = pipeline.run(
110
  prompt,
111
  seed=seed,
@@ -119,17 +118,15 @@ def text_to_3d(
119
  "cfg_strength": slat_guidance_strength,
120
  },
121
  )
122
- video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
123
- video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
124
- video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
125
- video_path = os.path.join(user_dir, 'sample.mp4')
126
- imageio.mimsave(video_path, video, fps=15)
127
  state = pack_state(outputs['gaussian'][0], outputs['mesh'][0])
 
 
 
 
128
  torch.cuda.empty_cache()
129
- return state, video_path
130
 
131
 
132
- @spaces.GPU(duration=90)
133
  def extract_glb(
134
  state: dict,
135
  mesh_simplify: float,
@@ -156,7 +153,6 @@ def extract_glb(
156
  return glb_path, glb_path
157
 
158
 
159
- @spaces.GPU
160
  def extract_gaussian(state: dict, req: gr.Request) -> Tuple[str, str]:
161
  """
162
  Extract a Gaussian file from the 3D model.
@@ -271,4 +267,4 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
271
  if __name__ == "__main__":
272
  pipeline = TrellisTextTo3DPipeline.from_pretrained("JeffreyXiang/TRELLIS-text-xlarge")
273
  pipeline.cuda()
274
- demo.launch()
 
1
  import gradio as gr
 
2
 
3
  import os
4
  import shutil
 
29
 
30
  def end_session(req: gr.Request):
31
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
32
+ #shutil.rmtree(user_dir)
33
 
34
 
35
  def pack_state(gs: Gaussian, mesh: MeshExtractResult) -> dict:
 
79
  return np.random.randint(0, MAX_SEED) if randomize_seed else seed
80
 
81
 
 
82
  def text_to_3d(
83
  prompt: str,
84
  seed: int,
 
104
  str: The path to the video of the 3D model.
105
  """
106
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
107
+ os.makedirs(user_dir, exist_ok=True)
108
  outputs = pipeline.run(
109
  prompt,
110
  seed=seed,
 
118
  "cfg_strength": slat_guidance_strength,
119
  },
120
  )
 
 
 
 
 
121
  state = pack_state(outputs['gaussian'][0], outputs['mesh'][0])
122
+ ply_path = os.path.join(user_dir, 'point_cloud.ply')
123
+ gaussian_data = outputs['gaussian'][0]
124
+ with open(ply_path, "wb") as f:
125
+ gaussian_data.save_ply(f)
126
  torch.cuda.empty_cache()
127
+ return state, ply_path
128
 
129
 
 
130
  def extract_glb(
131
  state: dict,
132
  mesh_simplify: float,
 
153
  return glb_path, glb_path
154
 
155
 
 
156
  def extract_gaussian(state: dict, req: gr.Request) -> Tuple[str, str]:
157
  """
158
  Extract a Gaussian file from the 3D model.
 
267
  if __name__ == "__main__":
268
  pipeline = TrellisTextTo3DPipeline.from_pretrained("JeffreyXiang/TRELLIS-text-xlarge")
269
  pipeline.cuda()
270
+ demo.launch(show_error=True,server_name="0.0.0.0",server_port=20000)