dkatz2391 commited on
Commit
8be7eef
·
verified ·
1 Parent(s): 265dd44

internal same port server endpoint for json object state

Browse files
Files changed (1) hide show
  1. app.py +33 -1
app.py CHANGED
@@ -291,4 +291,36 @@ api_text_to_3d = gr.Interface(
291
  outputs=[gr.JSON(label="State (API only)"), gr.Textbox(label="Video Path")],
292
  allow_flagging="never",
293
  description="API endpoint for text_to_3d that returns the state as JSON. Not wired to UI."
294
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  outputs=[gr.JSON(label="State (API only)"), gr.Textbox(label="Video Path")],
292
  allow_flagging="never",
293
  description="API endpoint for text_to_3d that returns the state as JSON. Not wired to UI."
294
+ )
295
+
296
+ # Add FastAPI custom route for state object access
297
+ try:
298
+ from fastapi import FastAPI, Request
299
+ from fastapi.responses import JSONResponse
300
+ import uvicorn
301
+ app = demo.app if hasattr(demo, 'app') else None
302
+ if app:
303
+ @app.post("/api_text_to_3d")
304
+ async def api_text_to_3d_route(request: Request):
305
+ body = await request.json()
306
+ prompt = body.get("prompt")
307
+ seed = body.get("seed", 0)
308
+ ss_guidance_strength = body.get("ss_guidance_strength", 7.5)
309
+ ss_sampling_steps = body.get("ss_sampling_steps", 25)
310
+ slat_guidance_strength = body.get("slat_guidance_strength", 7.5)
311
+ slat_sampling_steps = body.get("slat_sampling_steps", 25)
312
+ # Create a dummy gr.Request
313
+ class DummyReq:
314
+ session_hash = "api"
315
+ state, video_path = text_to_3d(
316
+ prompt,
317
+ seed,
318
+ ss_guidance_strength,
319
+ ss_sampling_steps,
320
+ slat_guidance_strength,
321
+ slat_sampling_steps,
322
+ DummyReq()
323
+ )
324
+ return JSONResponse([state, video_path])
325
+ except Exception as e:
326
+ print(f"[WARN] Could not add FastAPI custom route: {e}")