Skip to content

Commit f4153c5

Browse files
committed
fix: simplify login flow & paper list UI
1 parent 075fd64 commit f4153c5

File tree

3 files changed

+74
-134
lines changed

3 files changed

+74
-134
lines changed

libs/ktem/ktem/pages/chat/__init__.py

Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -271,76 +271,72 @@ def on_building_ui(self):
271271
self.hint_page = HintPage(self._app)
272272

273273
with gr.Column(scale=6, elem_id="chat-area"):
274+
self.chat_panel = ChatPanel(self._app)
275+
274276
if KH_DEMO_MODE:
275277
self.paper_list = PaperListPage(self._app)
276278

277-
self.chat_panel = ChatPanel(self._app)
278-
279-
with gr.Row():
280-
with gr.Accordion(
281-
label="Chat settings",
282-
elem_id="chat-settings-expand",
283-
open=False,
284-
):
285-
with gr.Row(elem_id="quick-setting-labels"):
286-
gr.HTML("Reasoning method")
287-
gr.HTML("Model", visible=not KH_DEMO_MODE)
288-
gr.HTML("Language")
289-
290-
with gr.Row():
291-
reasoning_setting = (
292-
self._app.default_settings.reasoning.settings["use"]
293-
)
294-
model_setting = (
295-
self._app.default_settings.reasoning.options[
296-
"simple"
297-
].settings["llm"]
298-
)
299-
language_setting = (
300-
self._app.default_settings.reasoning.settings["lang"]
301-
)
302-
citation_setting = (
303-
self._app.default_settings.reasoning.options[
304-
"simple"
305-
].settings["highlight_citation"]
306-
)
279+
with gr.Accordion(
280+
label="Chat settings",
281+
elem_id="chat-settings-expand",
282+
open=False,
283+
visible=not KH_DEMO_MODE,
284+
) as self.chat_settings:
285+
with gr.Row(elem_id="quick-setting-labels"):
286+
gr.HTML("Reasoning method")
287+
gr.HTML("Model", visible=not KH_DEMO_MODE)
288+
gr.HTML("Language")
289+
290+
with gr.Row():
291+
reasoning_setting = (
292+
self._app.default_settings.reasoning.settings["use"]
293+
)
294+
model_setting = self._app.default_settings.reasoning.options[
295+
"simple"
296+
].settings["llm"]
297+
language_setting = (
298+
self._app.default_settings.reasoning.settings["lang"]
299+
)
300+
citation_setting = self._app.default_settings.reasoning.options[
301+
"simple"
302+
].settings["highlight_citation"]
307303

308-
self.reasoning_type = gr.Dropdown(
309-
choices=reasoning_setting.choices[:REASONING_LIMITS],
310-
value=reasoning_setting.value,
311-
container=False,
312-
show_label=False,
313-
)
314-
self.model_type = gr.Dropdown(
315-
choices=model_setting.choices,
316-
value=model_setting.value,
317-
container=False,
318-
show_label=False,
319-
visible=not KH_DEMO_MODE,
320-
)
321-
self.language = gr.Dropdown(
322-
choices=language_setting.choices,
323-
value=language_setting.value,
324-
container=False,
325-
show_label=False,
326-
)
304+
self.reasoning_type = gr.Dropdown(
305+
choices=reasoning_setting.choices[:REASONING_LIMITS],
306+
value=reasoning_setting.value,
307+
container=False,
308+
show_label=False,
309+
)
310+
self.model_type = gr.Dropdown(
311+
choices=model_setting.choices,
312+
value=model_setting.value,
313+
container=False,
314+
show_label=False,
315+
visible=not KH_DEMO_MODE,
316+
)
317+
self.language = gr.Dropdown(
318+
choices=language_setting.choices,
319+
value=language_setting.value,
320+
container=False,
321+
show_label=False,
322+
)
327323

328-
self.citation = gr.Dropdown(
329-
choices=citation_setting.choices,
330-
value=citation_setting.value,
331-
container=False,
332-
show_label=False,
333-
interactive=True,
334-
elem_id="citation-dropdown",
335-
)
324+
self.citation = gr.Dropdown(
325+
choices=citation_setting.choices,
326+
value=citation_setting.value,
327+
container=False,
328+
show_label=False,
329+
interactive=True,
330+
elem_id="citation-dropdown",
331+
)
336332

337-
self.use_mindmap = gr.State(value=True)
338-
self.use_mindmap_check = gr.Checkbox(
339-
label="Mindmap (on)",
340-
container=False,
341-
elem_id="use-mindmap-checkbox",
342-
value=True,
343-
)
333+
self.use_mindmap = gr.State(value=True)
334+
self.use_mindmap_check = gr.Checkbox(
335+
label="Mindmap (on)",
336+
container=False,
337+
elem_id="use-mindmap-checkbox",
338+
value=True,
339+
)
344340

345341
with gr.Column(
346342
scale=INFO_PANEL_SCALES[False], elem_id="chat-info-panel"
@@ -523,8 +519,8 @@ def on_register_events(self):
523519
]
524520
+ self._indices_input,
525521
).then(
526-
lambda: gr.update(visible=False),
527-
outputs=[self.paper_list.accordion],
522+
lambda: (gr.update(visible=False), gr.update(visible=True)),
523+
outputs=[self.paper_list.accordion, self.chat_settings],
528524
).then(
529525
fn=None,
530526
inputs=None,
@@ -678,8 +674,8 @@ def on_register_events(self):
678674

679675
if KH_DEMO_MODE:
680676
onConvSelect = onConvSelect.then(
681-
lambda: gr.update(visible=False),
682-
outputs=[self.paper_list.accordion],
677+
lambda: (gr.update(visible=False), gr.update(visible=True)),
678+
outputs=[self.paper_list.accordion, self.chat_settings],
683679
)
684680

685681
onConvSelect = (
@@ -804,8 +800,8 @@ def raise_error_on_state(state):
804800
outputs=[self.quick_urls],
805801
show_progress="hidden",
806802
).then(
807-
lambda: gr.update(visible=False),
808-
outputs=[self.paper_list.accordion],
803+
lambda: (gr.update(visible=False), gr.update(visible=True)),
804+
outputs=[self.paper_list.accordion, self.chat_settings],
809805
).then(
810806
fn=None,
811807
inputs=None,

libs/ktem/ktem/pages/chat/control.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,19 @@ def on_building_ui(self):
159159
with gr.Row():
160160
self.btn_demo_login = gr.Button(
161161
"Sign-in to create new chat",
162-
link="/login-app/",
163162
min_width=120,
164163
size="sm",
165164
scale=1,
166165
variant="primary",
167166
)
167+
_js_redirect = """
168+
() => {
169+
url = '/login' + window.location.search;
170+
window.open(url, '_blank');
171+
}
172+
"""
173+
self.btn_demo_login.click(None, js=_js_redirect)
174+
168175
self.btn_demo_logout = gr.Button(
169176
"Sign-out",
170177
min_width=120,

sso_app_demo.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from decouple import config
66
from fastapi import FastAPI, Request
77
from fastapi.responses import FileResponse
8-
from ktem.assets import KotaemonTheme
98
from starlette.config import Config
109
from starlette.middleware.sessions import SessionMiddleware
1110
from starlette.responses import RedirectResponse
@@ -25,30 +24,6 @@
2524
SECRET_KEY = config("SECRET_KEY", default="default-secret-key")
2625

2726

28-
save_api_key_js = """
29-
function(api_key) {
30-
setStorage('google_api_key', api_key);
31-
window.location.href = "/app";
32-
}
33-
"""
34-
35-
global_js = """
36-
function () {
37-
// store info in local storage
38-
globalThis.setStorage = (key, value) => {
39-
localStorage.setItem(key, value)
40-
}
41-
globalThis.getStorage = (key, value) => {
42-
item = localStorage.getItem(key);
43-
return item ? item : value;
44-
}
45-
globalThis.removeFromStorage = (key) => {
46-
localStorage.removeItem(key)
47-
}
48-
}
49-
"""
50-
51-
5227
def add_session_middleware(app):
5328
config_data = {
5429
"GOOGLE_CLIENT_ID": GOOGLE_CLIENT_ID,
@@ -98,11 +73,6 @@ async def logout(request: Request):
9873
async def login(request: Request):
9974
root_url = gr.route_utils.get_root_url(request, "/login", None)
10075
redirect_uri = f"{root_url}/auth"
101-
# If your app is running on https, you should ensure that the
102-
# `redirect_uri` is https, e.g. uncomment the following lines:
103-
#
104-
# from urllib.parse import urlparse, urlunparse
105-
# redirect_uri = urlunparse(urlparse(str(redirect_uri))._replace(scheme='https'))
10676
return await oauth.google.authorize_redirect(request, redirect_uri)
10777

10878

@@ -116,39 +86,6 @@ async def auth(request: Request):
11686
return RedirectResponse(url="/")
11787

11888

119-
with gr.Blocks(
120-
theme=KotaemonTheme(),
121-
css=gradio_app._css,
122-
js=global_js,
123-
) as login_demo:
124-
with gr.Column(elem_id="login-row"):
125-
gr.Markdown("<h1 style='text-align:center;'>Welcome to Kotaemon</h1>")
126-
gr.Button(
127-
"Login with Google",
128-
link="/login",
129-
variant="primary",
130-
elem_id="google-login",
131-
)
132-
# with gr.Accordion(
133-
# "Or use your own Gemini API key",
134-
# elem_id="user-api-key-wrapper",
135-
# open=False,
136-
# ):
137-
# api_key_input = gr.Textbox(
138-
# placeholder="API Key",
139-
# label="Enter your Gemini API key",
140-
# )
141-
# api_key_save_btn = gr.Button(
142-
# "Save",
143-
# )
144-
145-
# api_key_save_btn.click(
146-
# fn=lambda _: True,
147-
# inputs=[api_key_input],
148-
# js=save_api_key_js,
149-
# )
150-
151-
app = gr.mount_gradio_app(app, login_demo, path="/login-app")
15289
app = gr.mount_gradio_app(
15390
app,
15491
main_demo,

0 commit comments

Comments
 (0)