Spaces:
Running
Running
Commit ·
794de26
1
Parent(s): 9211c5d
Added cors
Browse files- app.py +10 -0
- ui/app/hooks/useSentinel.ts +4 -4
app.py
CHANGED
|
@@ -12,6 +12,7 @@ from threading import RLock
|
|
| 12 |
from typing import Any
|
| 13 |
|
| 14 |
from fastapi import FastAPI, HTTPException, Query
|
|
|
|
| 15 |
from fastapi.staticfiles import StaticFiles
|
| 16 |
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse, StreamingResponse
|
| 17 |
from pydantic import BaseModel
|
|
@@ -36,6 +37,15 @@ app = FastAPI(
|
|
| 36 |
version="1.0.0",
|
| 37 |
)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
@dataclass
|
| 40 |
class SessionEntry:
|
| 41 |
env: SentinelEnv | ClusterTrustEnv
|
|
|
|
| 12 |
from typing import Any
|
| 13 |
|
| 14 |
from fastapi import FastAPI, HTTPException, Query
|
| 15 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 16 |
from fastapi.staticfiles import StaticFiles
|
| 17 |
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse, StreamingResponse
|
| 18 |
from pydantic import BaseModel
|
|
|
|
| 37 |
version="1.0.0",
|
| 38 |
)
|
| 39 |
|
| 40 |
+
# Add CORS middleware to allow browser requests from frontend
|
| 41 |
+
app.add_middleware(
|
| 42 |
+
CORSMiddleware,
|
| 43 |
+
allow_origins=["*"], # Allow all origins (use specific domains in production)
|
| 44 |
+
allow_credentials=True,
|
| 45 |
+
allow_methods=["*"], # Allow all HTTP methods (GET, POST, OPTIONS, etc.)
|
| 46 |
+
allow_headers=["*"], # Allow all headers
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
@dataclass
|
| 50 |
class SessionEntry:
|
| 51 |
env: SentinelEnv | ClusterTrustEnv
|
ui/app/hooks/useSentinel.ts
CHANGED
|
@@ -92,12 +92,12 @@ export function useSentinel() {
|
|
| 92 |
|
| 93 |
/* load evaluation data once */
|
| 94 |
useEffect(() => {
|
| 95 |
-
fetch(
|
| 96 |
.then((r) => r.json())
|
| 97 |
.then(setEval)
|
| 98 |
.catch(() => null);
|
| 99 |
|
| 100 |
-
fetch(
|
| 101 |
.then((r) => r.ok ? r.text() : "")
|
| 102 |
.then((txt) => {
|
| 103 |
const table = new Map<string, ReplayRow>();
|
|
@@ -151,7 +151,7 @@ export function useSentinel() {
|
|
| 151 |
const payload = { task_type: t, seed: s };
|
| 152 |
setLastReq({ method: "POST", path: "/reset", body: payload });
|
| 153 |
try {
|
| 154 |
-
const res = await fetch(
|
| 155 |
method: "POST",
|
| 156 |
headers: { "Content-Type": "application/json" },
|
| 157 |
body: JSON.stringify(payload),
|
|
@@ -203,7 +203,7 @@ export function useSentinel() {
|
|
| 203 |
};
|
| 204 |
setLastReq({ method: "POST", path: `/step?session_id=${sid}`, body: payload });
|
| 205 |
try {
|
| 206 |
-
const res = await fetch(`/step?session_id=${encodeURIComponent(sid)}`, {
|
| 207 |
method: "POST",
|
| 208 |
headers: { "Content-Type": "application/json" },
|
| 209 |
body: JSON.stringify(payload),
|
|
|
|
| 92 |
|
| 93 |
/* load evaluation data once */
|
| 94 |
useEffect(() => {
|
| 95 |
+
fetch(`${process.env.NEXT_PUBLIC_API_URL}/assets/evaluation_results.json`)
|
| 96 |
.then((r) => r.json())
|
| 97 |
.then(setEval)
|
| 98 |
.catch(() => null);
|
| 99 |
|
| 100 |
+
fetch(`${process.env.NEXT_PUBLIC_API_URL}/assets/trained_policy_replay.jsonl`)
|
| 101 |
.then((r) => r.ok ? r.text() : "")
|
| 102 |
.then((txt) => {
|
| 103 |
const table = new Map<string, ReplayRow>();
|
|
|
|
| 151 |
const payload = { task_type: t, seed: s };
|
| 152 |
setLastReq({ method: "POST", path: "/reset", body: payload });
|
| 153 |
try {
|
| 154 |
+
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/reset`, {
|
| 155 |
method: "POST",
|
| 156 |
headers: { "Content-Type": "application/json" },
|
| 157 |
body: JSON.stringify(payload),
|
|
|
|
| 203 |
};
|
| 204 |
setLastReq({ method: "POST", path: `/step?session_id=${sid}`, body: payload });
|
| 205 |
try {
|
| 206 |
+
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/step?session_id=${encodeURIComponent(sid)}`, {
|
| 207 |
method: "POST",
|
| 208 |
headers: { "Content-Type": "application/json" },
|
| 209 |
body: JSON.stringify(payload),
|