rahul7star commited on
Commit
592f780
·
verified ·
1 Parent(s): 0433883

Update flux_train_ui.py

Browse files
Files changed (1) hide show
  1. flux_train_ui.py +12 -3
flux_train_ui.py CHANGED
@@ -466,9 +466,18 @@ def train_model_ui(data: str):
466
 
467
  # ⬇️ DO NOT remove this since you're keeping the manual launch
468
  if __name__ == "__main__":
469
- app = demo.launch(share=True, show_error=True, prevent_thread_lock=True)
 
470
 
471
- @app.post("/trigger")
 
 
 
 
 
 
 
 
472
  async def trigger(request: Request):
473
  try:
474
  body = await request.json()
@@ -478,7 +487,7 @@ if __name__ == "__main__":
478
  except Exception as e:
479
  return {"error": str(e)}
480
 
481
- app.block() # keep the server running
482
 
483
 
484
 
 
466
 
467
  # ⬇️ DO NOT remove this since you're keeping the manual launch
468
  if __name__ == "__main__":
469
+ # Unpack launch return value if it's a tuple
470
+ result = demo.launch(share=True, show_error=True, prevent_thread_lock=True)
471
 
472
+ if isinstance(result, tuple):
473
+ server = result[0]
474
+ else:
475
+ server = result
476
+
477
+ # Try to get the FastAPI app object
478
+ fastapi_app = getattr(server, "app", None) or getattr(server, "server", None).app
479
+
480
+ @fastapi_app.post("/trigger")
481
  async def trigger(request: Request):
482
  try:
483
  body = await request.json()
 
487
  except Exception as e:
488
  return {"error": str(e)}
489
 
490
+ server.block_thread()
491
 
492
 
493