| """Gradio Server assembly. |
| |
| Builds the ``gradio.Server`` (FastAPI-style API through Gradio), registers the |
| backend endpoints, and serves the **custom HTML/JS frontend** at the site root. |
| |
| The frontend (``src/frontend/index.html`` + ``static/``) is a hand-authored |
| single-page app β onboarding wizard β salary dashboard β contextual rights chat β |
| that calls the registered ``@app.api`` endpoints (``/dashboard``, ``/chat``, |
| ``/parse_lonstatistik``) via the Gradio JS client. This is the "off-brand" custom |
| UI; Gradio's own theming is not used here. |
| |
| See: https://huggingface.co/blog/introducing-gradio-server |
| """ |
|
|
| from __future__ import annotations |
|
|
| from pathlib import Path |
|
|
| from fastapi.responses import FileResponse |
| from fastapi.staticfiles import StaticFiles |
| from gradio import Server |
|
|
| from .api.endpoints import register |
|
|
| |
| FRONTEND = Path(__file__).resolve().parents[1] / "frontend" |
| INDEX_HTML = FRONTEND / "index.html" |
| STATIC_DIR = FRONTEND / "static" |
|
|
|
|
| def build_server() -> Server: |
| """Create the configured Gradio Server with the custom frontend at ``/``.""" |
| app = Server() |
|
|
| |
| register(app) |
|
|
| |
| |
| app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static") |
|
|
| @app.get("/") |
| def _index() -> FileResponse: |
| return FileResponse(str(INDEX_HTML)) |
|
|
| return app |
|
|