From 7853fb1c8d701bb8b720b3907bdc50017911d6a6 Mon Sep 17 00:00:00 2001 From: oobabooga Date: Sun, 4 May 2025 18:58:37 -0300 Subject: [PATCH] Optimize the Chat tab (#6948) --- css/main.css | 34 +++++++++++----------------------- js/main.js | 8 +------- modules/ui_chat.py | 2 +- 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/css/main.css b/css/main.css index cf0dfde7..64e96ccc 100644 --- a/css/main.css +++ b/css/main.css @@ -389,7 +389,7 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { .chat { margin-left: auto; margin-right: auto; - min-height: var(--chat-height); + flex: 1; overflow-y: auto; display: flex; flex-direction: column; @@ -401,11 +401,9 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { } .chat-parent { - height: calc(100dvh - 98px - var(--input-delta)); + flex: 1; overflow: auto !important; - /* scroll-behavior: smooth; */ border-radius: 0 !important; - margin-bottom: var(--input-delta) !important; } .chat-parent .prose { @@ -422,8 +420,7 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { } .chat-parent.bigchat { - height: calc(100dvh - 98px - var(--input-delta)) !important; - margin-bottom: var(--input-delta) !important; + flex: 1; } .chat > .messages { @@ -604,8 +601,6 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { } .chat-input-positioned { - position: absolute; - bottom: 0; max-width: 54rem; left: 50%; transform: translateX(-50%); @@ -790,7 +785,8 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { } #chat-input-container { - min-width: 0 !important; + display: flex; + flex-direction: column; } #chat-input-container > .form { @@ -799,9 +795,7 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { } #chat-input-row { - padding-bottom: 1.5em; - padding-left: 1rem; - padding-right: 1rem; + padding: 1rem; } #chat-input-row.bigchat { @@ -809,22 +803,16 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { } #chat-col { - padding-bottom: 100px; + height: 100dvh; + display: flex; + flex-direction: column; + padding-bottom: 0; } @media screen and (width <= 924px) { #chat-col { - padding-bottom: 100px; + height: calc(100dvh - 132px); margin-top: 32px; - position: relative; /* Ensure positioning for the pseudo-element */ - } - - .chat-parent { - height: calc(100dvh - 98px - var(--input-delta) - 32px); - } - - .chat-parent.bigchat { - height: calc(100dvh - 98px - var(--input-delta) - 32px) !important; } } diff --git a/js/main.js b/js/main.js index 33b7d6bd..408815db 100644 --- a/js/main.js +++ b/js/main.js @@ -442,12 +442,6 @@ function updateCssProperties() { // Check if the chat container is visible if (chatContainer.clientHeight > 0) { - const chatContainerParentHeight = chatContainer.parentNode.clientHeight; - const newChatHeight = `${chatContainerParentHeight - chatInputHeight - 80}px`; - - document.documentElement.style.setProperty("--chat-height", newChatHeight); - document.documentElement.style.setProperty("--input-delta", `${chatInputHeight - 40}px`); - // Adjust scrollTop based on input height change if (chatInputHeight !== currentChatInputHeight) { const deltaHeight = chatInputHeight - currentChatInputHeight; @@ -720,7 +714,7 @@ function isMobile() { // Function to initialize sidebars function initializeSidebars() { const isOnMobile = isMobile(); - + if (isOnMobile) { // Mobile state: Hide sidebars and set closed states [pastChatsRow, chatControlsRow, headerBar].forEach(el => { diff --git a/modules/ui_chat.py b/modules/ui_chat.py index 0d588549..0856cfab 100644 --- a/modules/ui_chat.py +++ b/modules/ui_chat.py @@ -46,8 +46,8 @@ def create_ui(): with gr.Row(): with gr.Column(elem_id='chat-col'): - shared.gradio['html_display'] = gr.HTML(value=chat_html_wrapper({'internal': [], 'visible': []}, '', '', 'chat', 'cai-chat', '')['html'], visible=True) shared.gradio['display'] = gr.JSON(value={}, visible=False) # Hidden buffer + shared.gradio['html_display'] = gr.HTML(value=chat_html_wrapper({'internal': [], 'visible': []}, '', '', 'chat', 'cai-chat', '')['html'], visible=True) with gr.Row(elem_id="chat-input-row"): with gr.Column(scale=1, elem_id='gr-hover-container'): gr.HTML(value='
', elem_id='gr-hover')