sanjay7676 commited on
Commit
2ed8ca5
·
1 Parent(s): 2b35bd5

fix(space): mount Gradio at / for HF iframe; disable SSR; curl path + blank UI notes; example step JSON

Browse files
Files changed (3) hide show
  1. README.md +7 -1
  2. app.py +10 -11
  3. examples/space_step.json +1 -0
README.md CHANGED
@@ -49,7 +49,7 @@ suggested_hardware: cpu-basic
49
 
50
  ### OpenEnv HTTP API on the Hugging Face Space
51
 
52
- The Space runs the same FastAPI routes as [`api_server.py`](api_server.py) on the **app root** (Gradio UI is at **`/ui`**; `/` redirects to `/ui`). There is **no `/start`** endpoint — begin an episode with **`POST /reset`**, then drive it with **`POST /step`**.
53
 
54
  1. **Base URL:** open the live Space, then use the **`*.hf.space`** host shown in the address bar (for this project it is typically **`https://sanjay7676-team404-forge.hf.space`**). If yours differs, copy it from the running app or from the Space **Embed** snippet.
55
  2. **Check liveness:** `curl -sS "https://sanjay7676-team404-forge.hf.space/health"`
@@ -64,6 +64,12 @@ curl -sS -X POST "https://sanjay7676-team404-forge.hf.space/step" \
64
 
65
  5. **Observe state:** `curl -sS "https://sanjay7676-team404-forge.hf.space/state"`
66
 
 
 
 
 
 
 
67
  **Note:** The Space shares **one** in-memory environment across all visitors — concurrent `reset` / `step` calls can interleave. For isolated runs, use **Docker** or **local** `api_server.py` on port `8000`.
68
 
69
  ### NOTE 1 — Non‑negotiable submission requirements (checklist)
 
49
 
50
  ### OpenEnv HTTP API on the Hugging Face Space
51
 
52
+ The Space runs the same FastAPI routes as [`api_server.py`](api_server.py) on the **app root**, with **Gradio at `/`** (same host as `/health`, `/reset`, `/step`, `/state`). There is **no `/start`** endpoint — begin an episode with **`POST /reset`**, then drive it with **`POST /step`**.
53
 
54
  1. **Base URL:** open the live Space, then use the **`*.hf.space`** host shown in the address bar (for this project it is typically **`https://sanjay7676-team404-forge.hf.space`**). If yours differs, copy it from the running app or from the Space **Embed** snippet.
55
  2. **Check liveness:** `curl -sS "https://sanjay7676-team404-forge.hf.space/health"`
 
64
 
65
  5. **Observe state:** `curl -sS "https://sanjay7676-team404-forge.hf.space/state"`
66
 
67
+ **Windows `curl` + `@step.json`:** `curl` resolves the file **relative to your current directory**. Either `cd` into the folder that contains `step.json`, or pass a full path, for example:
68
+
69
+ `curl.exe ... --data-binary "@examples/space_step.json"` (from repo root) or any **absolute** path to your JSON file.
70
+
71
+ **If the Hub “App” tab is blank:** open the **direct** Space URL in a new tab — `https://sanjay7676-team404-forge.hf.space/` (Gradio UI should load there). Allow third-party cookies for `huggingface.co` if the embedded App tab stays empty ([HF discussion](https://discuss.huggingface.co/t/cant-able-to-see-ui-when-the-model-is-running/56373)).
72
+
73
  **Note:** The Space shares **one** in-memory environment across all visitors — concurrent `reset` / `step` calls can interleave. For isolated runs, use **Docker** or **local** `api_server.py` on port `8000`.
74
 
75
  ### NOTE 1 — Non‑negotiable submission requirements (checklist)
app.py CHANGED
@@ -4,7 +4,6 @@ import gradio as gr
4
  import pandas as pd
5
  from typing import Any, Dict
6
  from fastapi import FastAPI
7
- from fastapi.responses import RedirectResponse
8
 
9
  from trainer import run_benchmark_mode, run_compare_mode
10
  from memory import CoachMemory
@@ -162,7 +161,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
162
  with gr.Tab("3. API Endpoints"):
163
  gr.Markdown("""
164
  ### OpenEnv API Standard
165
- FORGE-v4 exposes a FastAPI server on the **same origin** as this UI: routes live at the **site root**, while Gradio is under **`/ui`**. Locally, `python api_server.py` serves on **`:8000`**; on this Space, use your **`*.hf.space`** base URL (no separate `/start` — use **`POST /reset`** then **`POST /step`**).
166
 
167
  - **`GET /health`**: Liveness / version check.
168
  - **`POST /reset`**: Starts a new episode and returns the initial state.
@@ -185,15 +184,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
185
  outputs=[m_pass, m_def_reward, m_adv_reward, m_tier, plot_reward, plot_pass, memory_output],
186
  )
187
 
188
- space_app = gr.mount_gradio_app(api_app, demo, path="/ui")
189
-
190
-
191
- @space_app.get("/")
192
- async def root_redirect() -> RedirectResponse:
193
- return RedirectResponse(url="/ui", status_code=302)
194
-
195
-
196
- app = space_app
197
 
198
 
199
  if __name__ == "__main__":
 
4
  import pandas as pd
5
  from typing import Any, Dict
6
  from fastapi import FastAPI
 
7
 
8
  from trainer import run_benchmark_mode, run_compare_mode
9
  from memory import CoachMemory
 
161
  with gr.Tab("3. API Endpoints"):
162
  gr.Markdown("""
163
  ### OpenEnv API Standard
164
+ FORGE-v4 serves **Gradio at `/`** and the OpenEnv JSON routes at the **same origin** (`/health`, `/reset`, `/step`, `/state`). Locally, `python api_server.py` serves **API-only** on **`:8000`**; `python app.py` serves UI **+** API on **`:7860`**. On this Space, use your **`*.hf.space`** base URL (no `/start` — use **`POST /reset`** then **`POST /step`**).
165
 
166
  - **`GET /health`**: Liveness / version check.
167
  - **`POST /reset`**: Starts a new episode and returns the initial state.
 
184
  outputs=[m_pass, m_def_reward, m_adv_reward, m_tier, plot_reward, plot_pass, memory_output],
185
  )
186
 
187
+ # Mount Gradio at "/" so Hugging Face Spaces (hub iframe + *.hf.space) load assets and
188
+ # websockets from the same root. OpenEnv routes on api_app are registered before this mount
189
+ # and keep precedence over the Gradio catch-all.
190
+ app = gr.mount_gradio_app(
191
+ api_app,
192
+ demo,
193
+ path="/",
194
+ ssr_mode=False,
195
+ )
196
 
197
 
198
  if __name__ == "__main__":
examples/space_step.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"coder_code": "def solution(arr):\n return sorted(list(arr))", "coder_version": "demo"}