fix: hide chatbot column when welcome view is visible

Wrap thinking_box/chatbot/source_box in gr.Column(visible=False).
Show on first message send, hide again on reset/user switch.
All respond yields updated to include 9th chat_column output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-02 17:40:14 +09:00
co-authored by Claude Sonnet 4.6
parent a456650bc8
commit 3cb89b992c
+21 -20
View File
@@ -54,7 +54,7 @@ def transcribe_audio(filepath: str) -> str:
async def respond(message, history, show_thinking, user_id, use_tts, run_ids, image_path):
if not message.strip() and not image_path:
yield history, "", None, run_ids, "", "", None, gr.update()
yield history, "", None, run_ids, "", "", None, gr.update(), gr.update()
return
history = list(history)
@@ -64,8 +64,8 @@ async def respond(message, history, show_thinking, user_id, use_tts, run_ids, im
display_msg = f"🖼️ [이미지 첨부]\n{message}" if message.strip() else "🖼️ [이미지 첨부]"
history.append({"role": "user", "content": display_msg})
history.append({"role": "assistant", "content": ""})
# 첫 메시지 → 웰컴 뷰 숨기 (D4-2)
yield history, "", None, run_ids, "", "", None, gr.update(visible=False)
# 첫 메시지 → 웰컴 뷰 숨기고 챗봇 컬럼 표시 (D4-2)
yield history, "", None, run_ids, "", "", None, gr.update(visible=False), gr.update(visible=True)
collected_run_id = None
tts_text = ""
@@ -83,46 +83,46 @@ async def respond(message, history, show_thinking, user_id, use_tts, run_ids, im
if isinstance(token, dict) and "__status" in token:
if not thinking_acc:
yield history, "", None, run_ids, _status_html(token["__status"]), gr.update(), gr.update(), gr.update()
yield history, "", None, run_ids, _status_html(token["__status"]), gr.update(), gr.update(), gr.update(), gr.update()
continue
if isinstance(token, dict) and "__thinking" in token:
thinking_text += token["__thinking"]
thinking_acc += token["__thinking"]
yield history, "", None, run_ids, _live_html(_last_line(thinking_text)), gr.update(), gr.update(), gr.update()
yield history, "", None, run_ids, _live_html(_last_line(thinking_text)), gr.update(), gr.update(), gr.update(), gr.update()
continue
if isinstance(token, dict) and "__meta" in token:
thinking_acc += token["__meta"]
live = token["__meta"].strip()
if live:
yield history, "", None, run_ids, _live_html(live), gr.update(), gr.update(), gr.update()
yield history, "", None, run_ids, _live_html(live), gr.update(), gr.update(), gr.update(), gr.update()
continue
if isinstance(token, dict) and "__sources" in token:
yield history, "", None, run_ids, gr.update(), _sources_html(token["__sources"]), gr.update(), gr.update()
yield history, "", None, run_ids, gr.update(), _sources_html(token["__sources"]), gr.update(), gr.update(), gr.update()
continue
if thinking_acc and not thinking_finalized:
thinking_finalized = True
yield history, "", None, run_ids, _thinking_html(thinking_acc), gr.update(), gr.update(), gr.update()
yield history, "", None, run_ids, _thinking_html(thinking_acc), gr.update(), gr.update(), gr.update(), gr.update()
tts_text += token
history[-1]["content"] += token
yield history, "", None, run_ids, gr.update(), gr.update(), gr.update(), gr.update()
yield history, "", None, run_ids, gr.update(), gr.update(), gr.update(), gr.update(), gr.update()
except Exception as e:
history[-1]["content"] += f"\n\n[오류: {e}]"
yield history, "", None, run_ids, gr.update(), gr.update(), gr.update(), gr.update()
yield history, "", None, run_ids, gr.update(), gr.update(), gr.update(), gr.update(), gr.update()
return
run_ids.append(collected_run_id)
if use_tts:
audio_path = await container.tts_service().speak(tts_text)
yield history, "", audio_path, run_ids, gr.update(), gr.update(), gr.update(), gr.update()
yield history, "", audio_path, run_ids, gr.update(), gr.update(), gr.update(), gr.update(), gr.update()
else:
yield history, "", None, run_ids, gr.update(), gr.update(), gr.update(), gr.update()
yield history, "", None, run_ids, gr.update(), gr.update(), gr.update(), gr.update(), gr.update()
async def handle_feedback(like_data: gr.LikeData, history, run_ids, user_id):
@@ -145,7 +145,7 @@ async def handle_feedback(like_data: gr.LikeData, history, run_ids, user_id):
def switch_user(user_id):
return [], [], gr.update(value=_welcome_html(user_id), visible=True)
return [], [], gr.update(value=_welcome_html(user_id), visible=True), gr.update(visible=False)
async def reset_chat(user_id):
@@ -153,7 +153,7 @@ async def reset_chat(user_id):
await container.chat_service().reset(user_id)
except Exception as e:
logger.error("대화 초기화 실패: %s", e)
return [], [], gr.update(visible=True)
return [], [], gr.update(visible=True), gr.update(visible=False)
async def export_chat(history):
@@ -730,9 +730,10 @@ with gr.Blocks(title="율봇", css=_CUSTOM_CSS, theme=_THEME, js=_JS) as demo:
elem_classes=["welcome-wrap"],
)
thinking_box = gr.HTML(value="")
chatbot = gr.Chatbot(label="율봇", height=460, elem_id="main-chatbot")
source_box = gr.HTML(value="")
with gr.Column(visible=False) as chat_column:
thinking_box = gr.HTML(value="")
chatbot = gr.Chatbot(label="율봇", height=460, elem_id="main-chatbot")
source_box = gr.HTML(value="")
# D4-3: Pill 입력창
with gr.Row(elem_classes=["input-row"]):
@@ -829,17 +830,17 @@ with gr.Blocks(title="율봇", css=_CUSTOM_CSS, theme=_THEME, js=_JS) as demo:
user_selector.change(
switch_user,
inputs=[user_selector],
outputs=[chatbot, run_ids_state, welcome_view],
outputs=[chatbot, run_ids_state, welcome_view, chat_column],
).then(lambda u: u, inputs=[user_selector], outputs=[user_state])
transcribe_btn.click(transcribe_audio, inputs=[audio_input], outputs=[msg_box])
_respond_inputs = [msg_box, chatbot, show_thinking, user_state, use_tts, run_ids_state, image_input]
_respond_outputs = [chatbot, msg_box, tts_output, run_ids_state, thinking_box, source_box, image_input, welcome_view]
_respond_outputs = [chatbot, msg_box, tts_output, run_ids_state, thinking_box, source_box, image_input, welcome_view, chat_column]
send_btn.click(respond, inputs=_respond_inputs, outputs=_respond_outputs)
msg_box.submit(respond, inputs=_respond_inputs, outputs=_respond_outputs)
reset_btn.click(reset_chat, inputs=[user_state], outputs=[chatbot, run_ids_state, welcome_view])
reset_btn.click(reset_chat, inputs=[user_state], outputs=[chatbot, run_ids_state, welcome_view, chat_column])
export_btn.click(export_chat, inputs=[chatbot], outputs=[export_file])
chatbot.like(handle_feedback, inputs=[chatbot, run_ids_state, user_state], outputs=[])