Spaces:
Running
Running
Update flux_train_ui.py
Browse files- 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 |
-
|
469 |
-
|
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 |
-
|
478 |
-
|
479 |
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
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 |
|