Yosun commited on
Commit
a90db8a
·
1 Parent(s): 9053ad6

Ensure demo.launch() in __main__ for ZeroGPU @spaces.GPU function detection

Browse files
Files changed (1) hide show
  1. app.py +17 -19
app.py CHANGED
@@ -14,7 +14,7 @@ from media_loader import load_media_views
14
  from zipsplat import ZipSplat, viz
15
 
16
  # ----------------------------------------------------------------------------
17
- # Output Directory & FastAPI Application
18
  # ----------------------------------------------------------------------------
19
 
20
  OUT_DIR = Path("outputs").resolve()
@@ -32,21 +32,6 @@ def get_viewer_template() -> str:
32
  return ""
33
 
34
 
35
- app = FastAPI()
36
-
37
-
38
- @app.get("/api/ply/{file_id}")
39
- async def get_ply(file_id: str):
40
- file_path = OUT_DIR / f"{file_id}.ply"
41
- if file_path.exists():
42
- return FileResponse(
43
- str(file_path),
44
- media_type="application/octet-stream",
45
- headers={"Access-Control-Allow-Origin": "*"},
46
- )
47
- return HTMLResponse("PLY file not found", status_code=404)
48
-
49
-
50
  def normalize_uploaded_paths(files: Any) -> List[Path]:
51
  """Normalize Gradio return types (None, str, Path, list, dict, file objects) to a list of Path objects."""
52
  if files is None:
@@ -215,9 +200,22 @@ with gr.Blocks(title="ZipSplatPlus: 3D Gaussian Splatting with Interactive Viewe
215
  outputs=[video_out, file_out, viewer_out, status_out],
216
  )
217
 
218
- # Mount Gradio demo onto FastAPI app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  app = gr.mount_gradio_app(app, demo, path="/", allowed_paths=[str(OUT_DIR), tempfile.gettempdir()])
220
 
221
  if __name__ == "__main__":
222
- import uvicorn
223
- uvicorn.run("app:app", host="0.0.0.0", port=7860)
 
14
  from zipsplat import ZipSplat, viz
15
 
16
  # ----------------------------------------------------------------------------
17
+ # Output Directory & Storage
18
  # ----------------------------------------------------------------------------
19
 
20
  OUT_DIR = Path("outputs").resolve()
 
32
  return ""
33
 
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  def normalize_uploaded_paths(files: Any) -> List[Path]:
36
  """Normalize Gradio return types (None, str, Path, list, dict, file objects) to a list of Path objects."""
37
  if files is None:
 
200
  outputs=[video_out, file_out, viewer_out, status_out],
201
  )
202
 
203
+ # FastAPI app for serving raw PLY files
204
+ app = FastAPI()
205
+
206
+ @app.get("/api/ply/{file_id}")
207
+ async def get_ply(file_id: str):
208
+ file_path = OUT_DIR / f"{file_id}.ply"
209
+ if file_path.exists():
210
+ return FileResponse(
211
+ str(file_path),
212
+ media_type="application/octet-stream",
213
+ headers={"Access-Control-Allow-Origin": "*"},
214
+ )
215
+ return HTMLResponse("PLY file not found", status_code=404)
216
+
217
+ # Mount Gradio app onto FastAPI
218
  app = gr.mount_gradio_app(app, demo, path="/", allowed_paths=[str(OUT_DIR), tempfile.gettempdir()])
219
 
220
  if __name__ == "__main__":
221
+ demo.launch()