scvcoder commited on
Commit
3264ba1
·
verified ·
1 Parent(s): 00d343f

Redirect / -> /split (insert route at index 0 to override Gradio's /)

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -112,13 +112,14 @@ def _attach_split_view() -> None:
112
  """`/split` endpoint — Open WebUI iframe + 참고자료 polling 분할 레이아웃.
113
 
114
  KPAA local 의 _SPLIT_HTML 을 그대로 재사용하되 iframe src 만 UI Space URL 로
115
- 교체. /api/last-references polling 같은 origin (backend Space) 에서 받음.
 
116
  """
117
- from fastapi.responses import HTMLResponse
 
118
 
119
  from kpaa.server import _SPLIT_HTML
120
 
121
- # Local 은 localhost:8080 (Open WebUI), HF 에서는 UI Space URL.
122
  UI_SPACE_URL = "https://scvcoder-korean-privacy-ai-assistant.hf.space"
123
  hf_html = _SPLIT_HTML.replace(
124
  'src="http://localhost:8080/"',
@@ -129,9 +130,16 @@ def _attach_split_view() -> None:
129
  async def split_view() -> str:
130
  return hf_html
131
 
132
- # 사용자 편의: 루트 접속 시 /split 으로 리다이렉트할까 했지만 Gradio
133
- # / 를 점유하므로 /split 으로 직접 접속하도록 안내.
134
- print(f"[kpaa-backend] /split route added (UI iframe -> {UI_SPACE_URL})", flush=True)
 
 
 
 
 
 
 
135
 
136
 
137
  if __name__ == "__main__":
 
112
  """`/split` endpoint — Open WebUI iframe + 참고자료 polling 분할 레이아웃.
113
 
114
  KPAA local 의 _SPLIT_HTML 을 그대로 재사용하되 iframe src 만 UI Space URL 로
115
+ 교체. / 접속 시 /split 으로 리다이렉트 Gradio / 점유하지만 우리
116
+ redirect 라우트를 routes 리스트 *앞* 에 끼워넣어 우선권 획득.
117
  """
118
+ from fastapi.responses import HTMLResponse, RedirectResponse
119
+ from fastapi.routing import APIRoute
120
 
121
  from kpaa.server import _SPLIT_HTML
122
 
 
123
  UI_SPACE_URL = "https://scvcoder-korean-privacy-ai-assistant.hf.space"
124
  hf_html = _SPLIT_HTML.replace(
125
  'src="http://localhost:8080/"',
 
130
  async def split_view() -> str:
131
  return hf_html
132
 
133
+ # / /split 리다이렉트 (Gradio 보다 우선)
134
+ async def _root_redirect():
135
+ return RedirectResponse(url="/split", status_code=302)
136
+
137
+ demo.app.routes.insert(
138
+ 0,
139
+ APIRoute("/", _root_redirect, methods=["GET"], include_in_schema=False),
140
+ )
141
+
142
+ print(f"[kpaa-backend] /split + / redirect added (UI iframe -> {UI_SPACE_URL})", flush=True)
143
 
144
 
145
  if __name__ == "__main__":