longh37 commited on
Commit
acfbbe4
·
verified ·
1 Parent(s): 01ae32f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -15
app.py CHANGED
@@ -8,8 +8,6 @@ import uuid
8
  import spaces
9
 
10
  # --- FIX: make gradio compatible by downgrading huggingface_hub -----------
11
- # original gradio (4.x) expects huggingface_hub to still have HfFolder
12
- # so we just ensure we're on a <1.0.0 version
13
  subprocess.run(
14
  shlex.split("pip install 'huggingface_hub<1.0.0'"),
15
  check=False,
@@ -17,6 +15,7 @@ subprocess.run(
17
  # --------------------------------------------------------------------------
18
 
19
  import gradio as gr # import AFTER the pip install above
 
20
 
21
  # install custom wheels for gaussian splatting
22
  subprocess.run(shlex.split("pip install wheel/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl"))
@@ -33,12 +32,13 @@ from dust3r.image_pairs import make_pairs
33
  from dust3r.cloud_opt import global_aligner, GlobalAlignerMode
34
  from utils.dust3r_utils import compute_global_alignment, load_images, storePly, save_colmap_cameras, save_colmap_images
35
 
36
- from argparse import ArgumentParser, Namespace
37
  from arguments import ModelParams, PipelineParams, OptimizationParams
38
  from train_joint import training
39
  from render_by_interp import render_sets
40
 
41
  GRADIO_CACHE_FOLDER = './gradio_cache_folder'
 
42
  #############################################################################################################################################
43
 
44
 
@@ -106,7 +106,7 @@ def process(inputfiles, input_path=None):
106
 
107
  pairs = make_pairs(images, scene_graph='complete', prefilter=None, symmetrize=True)
108
  output = inference(pairs, model, opt.device, batch_size=opt.batch_size)
109
- output_colmap_path = img_folder_path.replace("images", "sparse/0")
110
  os.makedirs(output_colmap_path, exist_ok=True)
111
 
112
  scene = global_aligner(output, device=opt.device, mode=GlobalAlignerMode.PointCloudOptimizer)
@@ -151,7 +151,7 @@ def process(inputfiles, input_path=None):
151
  parser.add_argument("--save_iterations", nargs="+", type=int, default=[])
152
  parser.add_argument("--checkpoint_iterations", nargs="+", type=int, default=[])
153
  parser.add_argument("--start_checkpoint", type=str, default = None)
154
- parser.add_argument("--scene", type=str, default="demo")
155
  parser.add_argument("--n_views", type=int, default=3)
156
  parser.add_argument("--get_video", action="store_true")
157
  parser.add_argument("--optim_pose", type=bool, default=True)
@@ -188,7 +188,7 @@ def process(inputfiles, input_path=None):
188
  output_ply_path = opt.img_base_path + f'/output/point_cloud/iteration_{args.iteration}/point_cloud.ply'
189
  output_video_path = opt.img_base_path + f'/output/demo_{opt.n_views}_view.mp4'
190
 
191
- # sanity checks so Gradio shows a clear error if something went wrong
192
  if not os.path.exists(output_ply_path):
193
  print("PLY not found at:", output_ply_path)
194
  raise gr.Error(f"PLY file not found at {output_ply_path}")
@@ -197,8 +197,28 @@ def process(inputfiles, input_path=None):
197
  print("Video not found at:", output_video_path)
198
  raise gr.Error(f"Video file not found at {output_video_path}")
199
 
200
- # return video, ply-for-download, ply-for-3d-viewer
201
- return output_video_path, output_ply_path, output_ply_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  ##################################################################################################################################################
203
 
204
 
@@ -228,12 +248,10 @@ _DESCRIPTION = '''
228
  '''
229
 
230
 
231
- # block = gr.Blocks(title=_TITLE).queue()
232
  block = gr.Blocks().queue()
233
  with block:
234
  with gr.Row():
235
  with gr.Column(scale=1):
236
- # gr.Markdown('# ' + _TITLE)
237
  gr.Markdown(_DESCRIPTION)
238
 
239
  with gr.Row(variant='panel'):
@@ -258,9 +276,9 @@ with block:
258
  </div>
259
  """
260
  )
261
- output_file = gr.File(
262
- label="Download .ply",
263
- file_types=[".ply"],
264
  )
265
  with gr.Column(scale=1):
266
  output_video = gr.Video(label="video")
@@ -270,8 +288,6 @@ with block:
270
  gr.Examples(
271
  examples=[
272
  "sora-santorini-3-views",
273
- # "TT-family-3-views",
274
- # "dl3dv-ba55-3-views",
275
  ],
276
  inputs=[input_path],
277
  outputs=[output_video, output_file, output_model],
@@ -279,4 +295,5 @@ with block:
279
  cache_examples=True,
280
  label='Sparse-view Examples'
281
  )
 
282
  block.launch(server_name="0.0.0.0", share=False)
 
8
  import spaces
9
 
10
  # --- FIX: make gradio compatible by downgrading huggingface_hub -----------
 
 
11
  subprocess.run(
12
  shlex.split("pip install 'huggingface_hub<1.0.0'"),
13
  check=False,
 
15
  # --------------------------------------------------------------------------
16
 
17
  import gradio as gr # import AFTER the pip install above
18
+ from huggingface_hub import HfApi
19
 
20
  # install custom wheels for gaussian splatting
21
  subprocess.run(shlex.split("pip install wheel/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl"))
 
32
  from dust3r.cloud_opt import global_aligner, GlobalAlignerMode
33
  from utils.dust3r_utils import compute_global_alignment, load_images, storePly, save_colmap_cameras, save_colmap_images
34
 
35
+ from argparse import ArgumentParser
36
  from arguments import ModelParams, PipelineParams, OptimizationParams
37
  from train_joint import training
38
  from render_by_interp import render_sets
39
 
40
  GRADIO_CACHE_FOLDER = './gradio_cache_folder'
41
+ SPACE_REPO_ID = "longh37/InstantSplat" # <== your Space id
42
  #############################################################################################################################################
43
 
44
 
 
106
 
107
  pairs = make_pairs(images, scene_graph='complete', prefilter=None, symmetrize=True)
108
  output = inference(pairs, model, opt.device, batch_size=opt.batch_size)
109
+ output_colmap_path=img_folder_path.replace("images", "sparse/0")
110
  os.makedirs(output_colmap_path, exist_ok=True)
111
 
112
  scene = global_aligner(output, device=opt.device, mode=GlobalAlignerMode.PointCloudOptimizer)
 
151
  parser.add_argument("--save_iterations", nargs="+", type=int, default=[])
152
  parser.add_argument("--checkpoint_iterations", nargs="+", type=int, default=[])
153
  parser.add_argument("--start_checkpoint", type=str, default = None)
154
+ parser.add_argument("--scene", type=int, default="demo")
155
  parser.add_argument("--n_views", type=int, default=3)
156
  parser.add_argument("--get_video", action="store_true")
157
  parser.add_argument("--optim_pose", type=bool, default=True)
 
188
  output_ply_path = opt.img_base_path + f'/output/point_cloud/iteration_{args.iteration}/point_cloud.ply'
189
  output_video_path = opt.img_base_path + f'/output/demo_{opt.n_views}_view.mp4'
190
 
191
+ # sanity checks
192
  if not os.path.exists(output_ply_path):
193
  print("PLY not found at:", output_ply_path)
194
  raise gr.Error(f"PLY file not found at {output_ply_path}")
 
197
  print("Video not found at:", output_video_path)
198
  raise gr.Error(f"Video file not found at {output_video_path}")
199
 
200
+ # ------ (4) upload .ply to this Space repo & build URL ------
201
+ ply_url = None
202
+ rel_remote_path = f"outputs/{tmp_user_folder}_point_cloud.ply"
203
+ try:
204
+ api = HfApi()
205
+ api.upload_file(
206
+ repo_id=SPACE_REPO_ID,
207
+ repo_type="space",
208
+ path_or_fileobj=output_ply_path,
209
+ path_in_repo=rel_remote_path,
210
+ )
211
+ ply_url = f"https://huggingface.co/spaces/{SPACE_REPO_ID}/resolve/main/{rel_remote_path}"
212
+ print("Uploaded PLY to:", ply_url)
213
+ except Exception as e:
214
+ print("Failed to upload PLY to hub:", e)
215
+ ply_url = f"LOCAL:{output_ply_path}"
216
+
217
+ # return:
218
+ # 1) video path (for gr.Video)
219
+ # 2) ply URL (for API + textbox)
220
+ # 3) local ply path (for gr.Model3D viewer)
221
+ return output_video_path, ply_url, output_ply_path
222
  ##################################################################################################################################################
223
 
224
 
 
248
  '''
249
 
250
 
 
251
  block = gr.Blocks().queue()
252
  with block:
253
  with gr.Row():
254
  with gr.Column(scale=1):
 
255
  gr.Markdown(_DESCRIPTION)
256
 
257
  with gr.Row(variant='panel'):
 
276
  </div>
277
  """
278
  )
279
+ output_file = gr.Textbox(
280
+ label="PLY download URL",
281
+ interactive=False,
282
  )
283
  with gr.Column(scale=1):
284
  output_video = gr.Video(label="video")
 
288
  gr.Examples(
289
  examples=[
290
  "sora-santorini-3-views",
 
 
291
  ],
292
  inputs=[input_path],
293
  outputs=[output_video, output_file, output_model],
 
295
  cache_examples=True,
296
  label='Sparse-view Examples'
297
  )
298
+
299
  block.launch(server_name="0.0.0.0", share=False)