From 18609a4f7d82569e505aba929e5e482fb8c7f176 Mon Sep 17 00:00:00 2001 From: sal Date: Mon, 1 Jun 2026 13:34:47 +0900 Subject: [PATCH] Collapsible thinking box with details/summary, thinking on by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Thinking box uses
/ — collapsed by default, expands on click - Simple __status header shown before content arrives (no expand needed) - show_thinking checkbox default changed to True Co-Authored-By: Claude Sonnet 4.6 --- app.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index c361b86..c1dfb15 100644 --- a/app.py +++ b/app.py @@ -118,8 +118,9 @@ async def respond(message, history, show_thinking, user_id, use_tts, run_ids): # 즉시 상태 표시 — thinking_acc에 누적하지 않음 (임시 메시지) if isinstance(token, dict) and "__status" in token: - status_text = (thinking_acc + "\n\n" + token["__status"]) if thinking_acc else token["__status"] - yield history, "", None, run_ids, _thinking_html(status_text) + if not thinking_acc: + yield history, "", None, run_ids, _status_html(token["__status"]) + # thinking_acc에 내용 있으면 기존 표시 유지 continue # 사고 과정(LLM thinking) — 박스에 추가 @@ -228,21 +229,35 @@ def delete_doc(source): # ── UI 구성 ────────────────────────────────────────────────────── -_THINKING_STYLE = ( +_BOX_STYLE = ( "background:#f9f9f9;border-left:3px solid #bbb;border-radius:6px;" - "padding:10px 14px;max-height:220px;overflow-y:auto;" - "font-size:0.85em;color:#555;white-space:pre-wrap;margin-bottom:6px;" + "padding:8px 14px;margin-bottom:6px;" +) +_CONTENT_STYLE = ( + "margin-top:8px;white-space:pre-wrap;font-size:0.85em;" + "color:#555;max-height:200px;overflow-y:auto;" ) def _thinking_html(text: str, done: bool = False) -> str: + """접기/펼치기 가능한 사고 과정 박스.""" icon = "💭" if done else "🤔" label = "분석 완료" if done else "분석 중..." cursor = "" if done else " ▌" return ( - f'
' - f"{icon} {label}

" - f"{_html.escape(text)}{cursor}
" + f'
' + f'{icon} {label}' + f'
{_html.escape(text)}{cursor}
' + f'
' + ) + + +def _status_html(status: str) -> str: + """내용 없이 상태만 표시하는 단순 헤더.""" + return ( + f'
' + f'🤔 {_html.escape(status)}' + f'
' ) @@ -282,7 +297,7 @@ with gr.Blocks(title="율봇") as demo: transcribe_btn = gr.Button("음성 → 텍스트 변환", scale=1) with gr.Row(): - show_thinking = gr.Checkbox(label="사고 과정 표시", value=False) + show_thinking = gr.Checkbox(label="사고 과정 표시", value=True) use_tts = gr.Checkbox(label="음성으로 답변 읽기 (TTS)", value=False) reset_btn = gr.Button("대화 초기화", size="sm")