GoutamSachdev commited on
Commit
d2796c3
Β·
1 Parent(s): 1b4a915

Show masked key fingerprint in UI; add Go-to-Chat button that switches tabs on completion

Browse files
docling_pdf_processor/web/gradio_app.py CHANGED
@@ -122,6 +122,22 @@ def _format_status(status: str) -> str:
122
  return f"{emoji} {status.upper()}"
123
 
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  # ── Event handlers ─────────────────────────────────────────────
126
 
127
  def process_pdf(
@@ -342,7 +358,7 @@ def main():
342
  "and chat with a **Hybrid RAG** system (Vector + Knowledge Graph + BM25)."
343
  )
344
 
345
- with gr.Tabs():
346
  with gr.Tab("Process PDF"):
347
  with gr.Accordion("πŸ”Œ API Status", open=True):
348
  api_status_md = gr.Markdown(
@@ -367,6 +383,12 @@ def main():
367
  value=DEFAULT_GROQ,
368
  placeholder="gsk_...",
369
  )
 
 
 
 
 
 
370
  vision_model = gr.Textbox(
371
  label="Vision Model",
372
  value=settings.vision_model,
@@ -423,8 +445,11 @@ def main():
423
  elem_classes="logs-box",
424
  value="Waiting for PDF upload...",
425
  )
 
 
 
426
 
427
- with gr.Tab("Chat"):
428
  chatbot = gr.Chatbot(label="Conversation", height=500, type="messages")
429
  with gr.Row():
430
  msg_input = gr.Textbox(
@@ -506,6 +531,15 @@ def main():
506
  outputs=[progress_slider, status_text, logs_box, chatbot, msg_input, state],
507
  )
508
 
 
 
 
 
 
 
 
 
 
509
  gr.Markdown("---")
510
  gr.Markdown(
511
  "πŸ’‘ **Privacy note:** Every session gets its own isolated workspace. "
 
122
  return f"{emoji} {status.upper()}"
123
 
124
 
125
+ def _mask_key(key: str | None) -> str:
126
+ """Mask a key for display: keep the public prefix + last 4 chars only."""
127
+ if not key:
128
+ return "(not set)"
129
+ for p in ("sk-or-v1-", "sk-or-", "gsk_", "sk-"):
130
+ if key.startswith(p):
131
+ tail = key[-4:] if len(key) > len(p) + 4 else ""
132
+ return f"{p}β€’β€’β€’β€’{tail}" if tail else f"{p}β€’β€’β€’β€’"
133
+ return "β€’β€’β€’β€’β€’β€’β€’β€’"
134
+
135
+
136
+ def _maybe_show_chat_btn(status: str) -> gr.Button:
137
+ """Reveal the 'Go to Chat' button only once the pipeline is 'ready'."""
138
+ return gr.Button(visible=(status == _format_status("ready")))
139
+
140
+
141
  # ── Event handlers ─────────────────────────────────────────────
142
 
143
  def process_pdf(
 
358
  "and chat with a **Hybrid RAG** system (Vector + Knowledge Graph + BM25)."
359
  )
360
 
361
+ with gr.Tabs() as tabs:
362
  with gr.Tab("Process PDF"):
363
  with gr.Accordion("πŸ”Œ API Status", open=True):
364
  api_status_md = gr.Markdown(
 
383
  value=DEFAULT_GROQ,
384
  placeholder="gsk_...",
385
  )
386
+ gr.Markdown(
387
+ f"πŸ”‘ **Loaded keys** β€” OpenRouter: `{_mask_key(DEFAULT_OPENROUTER)}` \n"
388
+ f"Groq: `{_mask_key(DEFAULT_GROQ)}` \n"
389
+ "_A blank-looking password field above is normal β€” the key is "
390
+ "loaded from the environment and the pipeline uses it automatically._"
391
+ )
392
  vision_model = gr.Textbox(
393
  label="Vision Model",
394
  value=settings.vision_model,
 
445
  elem_classes="logs-box",
446
  value="Waiting for PDF upload...",
447
  )
448
+ go_chat_btn = gr.Button(
449
+ "πŸ’¬ Go to Chat", variant="primary", visible=False
450
+ )
451
 
452
+ with gr.Tab("Chat", id="chat"):
453
  chatbot = gr.Chatbot(label="Conversation", height=500, type="messages")
454
  with gr.Row():
455
  msg_input = gr.Textbox(
 
531
  outputs=[progress_slider, status_text, logs_box, chatbot, msg_input, state],
532
  )
533
 
534
+ # Reveal the "Go to Chat" button once the pipeline reaches 'ready',
535
+ # and switch to the Chat tab when it is clicked.
536
+ status_text.change(
537
+ fn=_maybe_show_chat_btn,
538
+ inputs=[status_text],
539
+ outputs=[go_chat_btn],
540
+ )
541
+ go_chat_btn.click(fn=lambda: gr.Tabs(selected="chat"), outputs=[tabs])
542
+
543
  gr.Markdown("---")
544
  gr.Markdown(
545
  "πŸ’‘ **Privacy note:** Every session gets its own isolated workspace. "