dkatz2391 commited on
Commit
5faf466
·
verified ·
1 Parent(s): 8be7eef

Back to state object error

Browse files
Files changed (1) hide show
  1. app.py +1 -53
app.py CHANGED
@@ -271,56 +271,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()
275
- # Launch API-only endpoint for server-to-server use if API_ONLY is set
276
- if os.environ.get("API_ONLY"):
277
- api_text_to_3d.launch(server_port=7861)
278
-
279
- # API-only endpoint for server-to-server use: returns state as JSON
280
- api_text_to_3d = gr.Interface(
281
- fn=text_to_3d,
282
- inputs=[
283
- gr.Textbox(label="Text Prompt"),
284
- gr.Number(label="Seed", value=0),
285
- gr.Number(label="SS Guidance Strength", value=7.5),
286
- gr.Number(label="SS Sampling Steps", value=25),
287
- gr.Number(label="SLAT Guidance Strength", value=7.5),
288
- gr.Number(label="SLAT Sampling Steps", value=25),
289
- gr.Request(),
290
- ],
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}")
 
271
  if __name__ == "__main__":
272
  pipeline = TrellisTextTo3DPipeline.from_pretrained("JeffreyXiang/TRELLIS-text-xlarge")
273
  pipeline.cuda()
274
+ demo.launch()