Serve Gradio UI from Space root
Browse files- app.py +1 -7
- tests/test_api_contract.py +9 -1
app.py
CHANGED
|
@@ -5,7 +5,6 @@ from __future__ import annotations
|
|
| 5 |
import inspect
|
| 6 |
|
| 7 |
from fastapi import FastAPI
|
| 8 |
-
from fastapi.responses import RedirectResponse
|
| 9 |
|
| 10 |
from gamemaster_copilot.config import MODES, get_settings
|
| 11 |
from gamemaster_copilot.schemas import ChatRequest, ChatResponse
|
|
@@ -22,11 +21,6 @@ app = FastAPI(
|
|
| 22 |
)
|
| 23 |
|
| 24 |
|
| 25 |
-
@app.get("/", include_in_schema=False)
|
| 26 |
-
def root() -> RedirectResponse:
|
| 27 |
-
return RedirectResponse(url="/ui")
|
| 28 |
-
|
| 29 |
-
|
| 30 |
@app.get("/api/health")
|
| 31 |
def health() -> dict:
|
| 32 |
return service.health()
|
|
@@ -152,4 +146,4 @@ demo = _build_gradio_ui()
|
|
| 152 |
if demo is not None:
|
| 153 |
import gradio as gr
|
| 154 |
|
| 155 |
-
app = gr.mount_gradio_app(app, demo, path="/
|
|
|
|
| 5 |
import inspect
|
| 6 |
|
| 7 |
from fastapi import FastAPI
|
|
|
|
| 8 |
|
| 9 |
from gamemaster_copilot.config import MODES, get_settings
|
| 10 |
from gamemaster_copilot.schemas import ChatRequest, ChatResponse
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
@app.get("/api/health")
|
| 25 |
def health() -> dict:
|
| 26 |
return service.health()
|
|
|
|
| 146 |
if demo is not None:
|
| 147 |
import gradio as gr
|
| 148 |
|
| 149 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
tests/test_api_contract.py
CHANGED
|
@@ -6,6 +6,15 @@ from fastapi.testclient import TestClient # noqa: E402
|
|
| 6 |
from app import app # noqa: E402
|
| 7 |
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def test_api_chat_valid_request() -> None:
|
| 10 |
client = TestClient(app)
|
| 11 |
|
|
@@ -50,4 +59,3 @@ def test_api_chat_rejects_bad_mode_and_k() -> None:
|
|
| 50 |
)
|
| 51 |
|
| 52 |
assert response.status_code == 422
|
| 53 |
-
|
|
|
|
| 6 |
from app import app # noqa: E402
|
| 7 |
|
| 8 |
|
| 9 |
+
def test_root_serves_ui_without_redirect() -> None:
|
| 10 |
+
client = TestClient(app)
|
| 11 |
+
|
| 12 |
+
response = client.get("/", follow_redirects=False)
|
| 13 |
+
|
| 14 |
+
assert response.status_code == 200
|
| 15 |
+
assert "text/html" in response.headers["content-type"]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
def test_api_chat_valid_request() -> None:
|
| 19 |
client = TestClient(app)
|
| 20 |
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
assert response.status_code == 422
|
|
|