HF Spaces: initialize backend ConversationService on startup
Browse files
frontend/react_gradio_hybrid.py
CHANGED
|
@@ -21,6 +21,8 @@ sys.path.insert(0, str(project_root / "frontend"))
|
|
| 21 |
from config.settings import get_settings
|
| 22 |
from websocket_manager import WebSocketManager, ManagerState
|
| 23 |
from backend.api.main import app as backend_app
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Load settings
|
| 26 |
settings = get_settings()
|
|
@@ -36,6 +38,11 @@ app = FastAPI(title="AI Survey Simulator - React Frontend")
|
|
| 36 |
# Mount backend API under /api so the Space can run as a single process
|
| 37 |
app.mount("/api", backend_app)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
# Enable CORS for local development
|
| 40 |
app.add_middleware(
|
| 41 |
CORSMiddleware,
|
|
|
|
| 21 |
from config.settings import get_settings
|
| 22 |
from websocket_manager import WebSocketManager, ManagerState
|
| 23 |
from backend.api.main import app as backend_app
|
| 24 |
+
from backend.api.conversation_ws import manager as backend_ws_manager
|
| 25 |
+
from backend.api.conversation_service import initialize_conversation_service
|
| 26 |
|
| 27 |
# Load settings
|
| 28 |
settings = get_settings()
|
|
|
|
| 38 |
# Mount backend API under /api so the Space can run as a single process
|
| 39 |
app.mount("/api", backend_app)
|
| 40 |
|
| 41 |
+
@app.on_event("startup")
|
| 42 |
+
async def initialize_backend_services():
|
| 43 |
+
"""Initialize backend services when running the mounted backend inside this app."""
|
| 44 |
+
initialize_conversation_service(backend_ws_manager, settings)
|
| 45 |
+
|
| 46 |
# Enable CORS for local development
|
| 47 |
app.add_middleware(
|
| 48 |
CORSMiddleware,
|