spagestic commited on
Commit
cb3c4f4
·
1 Parent(s): 44f0c67

Update authentication prompts to direct users to the new Server-mode login link and adjust chat messages accordingly following the removal of the Gradio sidebar.

Browse files
.cursor/plans/server_ui_migration_f9399bac.plan.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: Server UI Migration
3
+ overview: Migrate Borderless from a Gradio component UI to a focused `gradio.Server` app with a custom HTML/JS frontend and queued API endpoints for chat and prompt generation. The first pass preserves the core globe, intake form, and chat workflow, while deferring saved-history/sidebar polish.
4
+ todos:
5
+ - id: verify-server-version
6
+ content: Install or select a Gradio version that exposes `gradio.Server` and update dependency metadata accordingly.
7
+ status: pending
8
+ - id: server-entrypoint
9
+ content: Refactor `app.py` to create a `Server`, serve the custom frontend, and launch the server app.
10
+ status: pending
11
+ - id: frontend-shell
12
+ content: Create a plain HTML/JS frontend that reuses existing globe assets and implements intake plus chat UI.
13
+ status: pending
14
+ - id: api-adapters
15
+ content: Add `@app.api()` adapters for prompt creation and chat responses, preserving globe state updates.
16
+ status: pending
17
+ - id: auth-check
18
+ content: Verify the HF OAuth/token path under `gradio.Server` and keep behavior explicit if full login UI is deferred.
19
+ status: pending
20
+ - id: smoke-test
21
+ content: Run import checks and a local smoke test for page serving, queued API calls, and globe updates.
22
+ status: pending
23
+ isProject: false
24
+ ---
25
+
26
+ # gradio.Server UI Migration
27
+
28
+ ## Goal
29
+ Move the app from the current `gr.Blocks` entrypoint in [`app.py`](/home/user/app/app.py) to `gradio.Server`, serving a custom frontend from FastAPI routes and exposing backend work through `@app.api()` so requests still use Gradio's queue/client infrastructure.
30
+
31
+ ## Current Shape
32
+ - [`app.py`](/home/user/app/app.py) builds `demo = create_demo()` with `gr.Blocks`, injects [`assets/app.css`](/home/user/app/assets/app.css) plus [`assets/globe_head.html`](/home/user/app/assets/globe_head.html), and launches `demo.launch()`.
33
+ - [`ui/workspace.py`](/home/user/app/ui/workspace.py) composes the UI from Gradio components: MapLibre globe, intake form tab, and `SidebarChatInterface`.
34
+ - [`ui/agent/respond.py`](/home/user/app/ui/agent/respond.py) is the backend chat generator. It already separates agent logic from Gradio layout, but it currently expects Gradio chat shapes and an injected `gr.OAuthToken`.
35
+ - Local [`requirements.txt`](/home/user/app/requirements.txt) pins `gradio==6.5.1`, and local introspection shows that version does not expose `gr.Server`; the migration needs a dependency bump to a Gradio release that includes `Server`.
36
+
37
+ ## Implementation Plan
38
+ 1. Update the runtime dependency to a Gradio version that provides `gradio.Server`.
39
+ - Align [`requirements.txt`](/home/user/app/requirements.txt) with the Space metadata in [`README.md`](/home/user/app/README.md), or use the latest available Gradio version if installation confirms `gr.Server` exists.
40
+ - After installing, verify with a small import check: `import gradio as gr; hasattr(gr, "Server")`.
41
+
42
+ 2. Replace the Gradio component entrypoint with a `Server` app in [`app.py`](/home/user/app/app.py).
43
+ - Create `app = Server()`.
44
+ - Add `@app.get("/")` to serve a static HTML frontend.
45
+ - Add routes for static assets, likely under `/assets/...`, using FastAPI static files or explicit file responses.
46
+ - Keep `app.launch(show_error=True)` under `if __name__ == "__main__"` and expose `app` at module scope for Spaces.
47
+
48
+ 3. Add a focused custom frontend.
49
+ - Create a static HTML app, likely [`assets/index.html`](/home/user/app/assets/index.html), plus a JS module such as [`assets/app.js`](/home/user/app/assets/app.js) if keeping the HTML manageable.
50
+ - Reuse existing [`assets/globe.js`](/home/user/app/assets/globe.js), [`assets/globe.css`](/home/user/app/assets/globe.css), and [`assets/app.css`](/home/user/app/assets/app.css), adapting selectors away from Gradio-generated DOM where needed.
51
+ - Build the MVP UI with three regions: hero/globe, intake form, and chat panel.
52
+ - Use `@gradio/client` from the browser to connect to `window.location.origin` and call server APIs through the queue.
53
+
54
+ 4. Expose API endpoints with `@app.api()`.
55
+ - Add a prompt-building endpoint wrapping [`ui/intake/prompts.py`](/home/user/app/ui/intake/prompts.py) so the frontend can turn form values into a chat message.
56
+ - Add a chat endpoint wrapping [`ui/agent/respond.py`](/home/user/app/ui/agent/respond.py). For the MVP, adapt request/response payloads explicitly instead of relying on `gr.ChatInterface` internals.
57
+ - Stream or incrementally return assistant updates if `Server`/JS client support it cleanly; otherwise return the final response plus updated globe state for the first pass.
58
+
59
+ 5. Handle authentication conservatively.
60
+ - The existing app uses `gr.LoginButton` and `gr.OAuthToken` injection. In a custom frontend, confirm how `Server` exposes HF OAuth/session data to `@app.api()` endpoints.
61
+ - If token injection is supported, pass the token through to the existing `respond` path.
62
+ - If it is not supported directly, preserve the current clear auth-required behavior and document that login UX is deferred for a follow-up, rather than weakening auth by accepting arbitrary client-supplied tokens.
63
+
64
+ 6. Validate locally.
65
+ - Run a syntax/import check after edits.
66
+ - Launch the app and verify `/` serves the custom UI.
67
+ - Verify the JS client can call the prompt and chat APIs.
68
+ - Smoke-test that `update_globe` tool results still call `window.BorderlessGlobe.applyState(...)` in the frontend.
69
+
70
+ ## Deferred From MVP
71
+ - Full Gradio sidebar chat history parity from [`ui/sidebar.py`](/home/user/app/ui/sidebar.py) and `SidebarChatInterface`.
72
+ - Fine-grained token-by-token streaming if the `Server` JS client path makes this significantly more involved than a queued final response.
73
+ - A React/Svelte build pipeline; the first pass should stay plain HTML/CSS/JS to minimize new dependencies.