import os import uvicorn from fastapi import FastAPI import gradio as gr from main_service import app as fastapi_app from commercial_dashboard import demo as gradio_demo # This is the secret sauce for Hugging Face: # Mount the FastAPI (Brain) and Gradio (Dashboard) on the same server! os.environ["UNIFIED_MODE"] = "1" app = FastAPI() # Mount existing Brain Service routes app.mount("/api", fastapi_app) @app.get("/health") def health(): return {"status": "ok", "components": ["fastapi", "gradio"]} # Wrap the Gradio App app = gr.mount_gradio_app(app, gradio_demo, path="/", allowed_paths=[os.getcwd()]) if __name__ == "__main__": # HF looks for an app running on port 7860 uvicorn.run(app, host="0.0.0.0", port=7860)