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:
@@ -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):
|
async def respond(message, history, show_thinking, user_id, use_tts, run_ids, image_path):
|
||||||
if not message.strip() and not 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
|
return
|
||||||
|
|
||||||
history = list(history)
|
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 "🖼️ [이미지 첨부]"
|
display_msg = f"🖼️ [이미지 첨부]\n{message}" if message.strip() else "🖼️ [이미지 첨부]"
|
||||||
history.append({"role": "user", "content": display_msg})
|
history.append({"role": "user", "content": display_msg})
|
||||||
history.append({"role": "assistant", "content": ""})
|
history.append({"role": "assistant", "content": ""})
|
||||||
# 첫 메시지 → 웰컴 뷰 숨기기 (D4-2)
|
# 첫 메시지 → 웰컴 뷰 숨기고 챗봇 컬럼 표시 (D4-2)
|
||||||
yield history, "", None, run_ids, "", "", None, gr.update(visible=False)
|
yield history, "", None, run_ids, "", "", None, gr.update(visible=False), gr.update(visible=True)
|
||||||
|
|
||||||
collected_run_id = None
|
collected_run_id = None
|
||||||
tts_text = ""
|
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 isinstance(token, dict) and "__status" in token:
|
||||||
if not thinking_acc:
|
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
|
continue
|
||||||
|
|
||||||
if isinstance(token, dict) and "__thinking" in token:
|
if isinstance(token, dict) and "__thinking" in token:
|
||||||
thinking_text += token["__thinking"]
|
thinking_text += token["__thinking"]
|
||||||
thinking_acc += 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
|
continue
|
||||||
|
|
||||||
if isinstance(token, dict) and "__meta" in token:
|
if isinstance(token, dict) and "__meta" in token:
|
||||||
thinking_acc += token["__meta"]
|
thinking_acc += token["__meta"]
|
||||||
live = token["__meta"].strip()
|
live = token["__meta"].strip()
|
||||||
if live:
|
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
|
continue
|
||||||
|
|
||||||
if isinstance(token, dict) and "__sources" in token:
|
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
|
continue
|
||||||
|
|
||||||
if thinking_acc and not thinking_finalized:
|
if thinking_acc and not thinking_finalized:
|
||||||
thinking_finalized = True
|
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
|
tts_text += token
|
||||||
history[-1]["content"] += 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:
|
except Exception as e:
|
||||||
history[-1]["content"] += f"\n\n[오류: {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
|
return
|
||||||
|
|
||||||
run_ids.append(collected_run_id)
|
run_ids.append(collected_run_id)
|
||||||
|
|
||||||
if use_tts:
|
if use_tts:
|
||||||
audio_path = await container.tts_service().speak(tts_text)
|
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:
|
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):
|
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):
|
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):
|
async def reset_chat(user_id):
|
||||||
@@ -153,7 +153,7 @@ async def reset_chat(user_id):
|
|||||||
await container.chat_service().reset(user_id)
|
await container.chat_service().reset(user_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("대화 초기화 실패: %s", e)
|
logger.error("대화 초기화 실패: %s", e)
|
||||||
return [], [], gr.update(visible=True)
|
return [], [], gr.update(visible=True), gr.update(visible=False)
|
||||||
|
|
||||||
|
|
||||||
async def export_chat(history):
|
async def export_chat(history):
|
||||||
@@ -730,6 +730,7 @@ with gr.Blocks(title="율봇", css=_CUSTOM_CSS, theme=_THEME, js=_JS) as demo:
|
|||||||
elem_classes=["welcome-wrap"],
|
elem_classes=["welcome-wrap"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
with gr.Column(visible=False) as chat_column:
|
||||||
thinking_box = gr.HTML(value="")
|
thinking_box = gr.HTML(value="")
|
||||||
chatbot = gr.Chatbot(label="율봇", height=460, elem_id="main-chatbot")
|
chatbot = gr.Chatbot(label="율봇", height=460, elem_id="main-chatbot")
|
||||||
source_box = gr.HTML(value="")
|
source_box = gr.HTML(value="")
|
||||||
@@ -829,17 +830,17 @@ with gr.Blocks(title="율봇", css=_CUSTOM_CSS, theme=_THEME, js=_JS) as demo:
|
|||||||
user_selector.change(
|
user_selector.change(
|
||||||
switch_user,
|
switch_user,
|
||||||
inputs=[user_selector],
|
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])
|
).then(lambda u: u, inputs=[user_selector], outputs=[user_state])
|
||||||
|
|
||||||
transcribe_btn.click(transcribe_audio, inputs=[audio_input], outputs=[msg_box])
|
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_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)
|
send_btn.click(respond, inputs=_respond_inputs, outputs=_respond_outputs)
|
||||||
msg_box.submit(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])
|
export_btn.click(export_chat, inputs=[chatbot], outputs=[export_file])
|
||||||
|
|
||||||
chatbot.like(handle_feedback, inputs=[chatbot, run_ids_state, user_state], outputs=[])
|
chatbot.like(handle_feedback, inputs=[chatbot, run_ids_state, user_state], outputs=[])
|
||||||
|
|||||||
Reference in New Issue
Block a user