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

Update flux_train_ui.py

Browse files
Files changed (1) hide show
  1. flux_train_ui.py +14 -21
flux_train_ui.py CHANGED
@@ -465,29 +465,22 @@ def train_model_ui(data: str):
465
 
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()
484
- input_data = body.get("input", "")
485
- result = train_model_ui(input_data)
486
- return {"result": result}
487
- except Exception as e:
488
- return {"error": str(e)}
489
-
490
- server.block_thread()
491
 
 
 
 
492
 
493
 
 
465
 
466
 
467
  # ⬇️ DO NOT remove this since you're keeping the manual launch
468
+ # Main FastAPI app
469
+ app = FastAPI()
 
 
 
 
 
 
470
 
471
+ # Mount the Gradio app at root ("/")
472
+ app = gr.mount_gradio_app(app, demo, path="/")
473
 
474
+ # Custom POST endpoint
475
+ @app.post("/trigger")
476
+ async def trigger(request: Request):
477
+ body = await request.json()
478
+ input_data = body.get("input", "")
479
+ result = train_model_ui(input_data)
480
+ return {"result": result}
 
 
 
 
481
 
482
+ # Run everything
483
+ if __name__ == "__main__":
484
+ uvicorn.run(app, host="0.0.0.0", port=7860)
485
 
486