multimodalart HF Staff commited on
Commit
17bd2cf
·
verified ·
1 Parent(s): 76b240a

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -89,7 +89,21 @@ def _build_evaluator() -> Any:
89
  return pipeline, evaluator
90
 
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  PIPELINE, EVALUATOR = _build_evaluator()
 
93
  CROP_RATIO = PIPELINE.preprocessing['crop_size_ratio']
94
  VIEW_LIMIT = int(PIPELINE.preprocessing['max_views'])
95
 
@@ -130,7 +144,7 @@ def _mesh_reprojections(mesh, extrinsics, intrinsics, resolution: int = 518) ->
130
  return images
131
 
132
 
133
- @spaces.GPU(duration=420)
134
  def reconstruct_views(images: List[str], seed: int = 1, remove_background: bool = False,
135
  progress=gr.Progress(track_tqdm=True)) -> Tuple[str, List[str], str, str, str]:
136
  """Reconstruct a 3D object from 2-4 uncalibrated views of it.
@@ -218,7 +232,7 @@ CSS = """
218
  .dark .gradio-container { background: var(--background-fill-primary); }
219
  """
220
 
221
- with gr.Blocks(title='GenSfM — Generative Structure from Motion', theme=THEME, css=CSS) as demo:
222
  gr.Markdown(
223
  """
224
  # GenSfM — Generative Structure from Motion with Native 3D Diffusion
@@ -290,4 +304,4 @@ with gr.Blocks(title='GenSfM — Generative Structure from Motion', theme=THEME,
290
 
291
  if __name__ == '__main__':
292
  TMP_DIR.mkdir(parents=True, exist_ok=True)
293
- demo.launch(mcp_server=True)
 
89
  return pipeline, evaluator
90
 
91
 
92
+ def _prefetch_rembg() -> None:
93
+ """Download the u2net matting model at boot, outside any GPU window.
94
+
95
+ rembg fetches u2net.onnx (~170 MB) on its first session; doing that here
96
+ keeps the download out of every visitor's ZeroGPU quota.
97
+ """
98
+ try:
99
+ import rembg
100
+ rembg.new_session('u2net')
101
+ except Exception as error: # noqa: BLE001 — optional path, never block boot
102
+ print(f'rembg prefetch skipped: {error}', flush=True)
103
+
104
+
105
  PIPELINE, EVALUATOR = _build_evaluator()
106
+ _prefetch_rembg()
107
  CROP_RATIO = PIPELINE.preprocessing['crop_size_ratio']
108
  VIEW_LIMIT = int(PIPELINE.preprocessing['max_views'])
109
 
 
144
  return images
145
 
146
 
147
+ @spaces.GPU(duration=45)
148
  def reconstruct_views(images: List[str], seed: int = 1, remove_background: bool = False,
149
  progress=gr.Progress(track_tqdm=True)) -> Tuple[str, List[str], str, str, str]:
150
  """Reconstruct a 3D object from 2-4 uncalibrated views of it.
 
232
  .dark .gradio-container { background: var(--background-fill-primary); }
233
  """
234
 
235
+ with gr.Blocks(title='GenSfM — Generative Structure from Motion') as demo:
236
  gr.Markdown(
237
  """
238
  # GenSfM — Generative Structure from Motion with Native 3D Diffusion
 
304
 
305
  if __name__ == '__main__':
306
  TMP_DIR.mkdir(parents=True, exist_ok=True)
307
+ demo.launch(theme=THEME, css=CSS, mcp_server=True)