241006-Gradio中Chatbot通过CSS自适应调整高度

A. 最终效果

B. 参考代码

python 复制代码
import gradio as gr

CSS = """
.contain { display: flex; flex-direction: column; }
.gradio-container { height: 100vh !important; } 
#component-0 { height: 100%; }
#chatbot { flex-grow: 1; overflow: auto;}
#tab_item_4 { height: calc(100vh - 83px);}
#tab_item_4 .gap { height: 100%; }
#tab_item_4 .gap #chatbot1 { flex-grow: 1; height: auto !important;}

#tab_item_5 { height: calc(100vh - 83px);}
#tab_item_5 .gap { height: 100%; }
#tab_item_5 .gap #chatbot2 { flex-grow: 1; height: auto !important;}
"""

with gr.Blocks(css=CSS) as demo:
    # with gr.Blocks() as demo:
    with gr.Tabs(elem_classes="tab_id_123"):
        with gr.Tab('I want this tap', elem_id="tab_item_4"):
            chatbot = gr.Chatbot(elem_id="chatbot1")
            msg = gr.Textbox()
            clear = gr.Button("Clear")

        with gr.Tab('I want this ta2p', elem_id="tab_item_5"):
            chatbot = gr.Chatbot(elem_id="chatbot2")
            msg = gr.Textbox()
            clear = gr.Button("Clear")


# with gr.Blocks(css=CSS) as demo:
#     chatbot = gr.Chatbot(elem_id="chatbot")
#     msg = gr.Textbox()
#     clear = gr.Button("Clear")

demo.launch(inbrowser=True, server_name='0.0.0.0', server_port=5001)
相关推荐
ᥬ 小月亮8 分钟前
webpack基础
前端·webpack
YongGit27 分钟前
探索 AI + MCP 渲染前端 UI
前端·后端·node.js
慧一居士1 小时前
<script setup>中的setup作用以及和不带的区别对比
前端
RainbowSea1 小时前
NVM 切换 Node 版本工具的超详细安装说明
java·前端
读书点滴2 小时前
笨方法学python -练习14
java·前端·python
Mintopia2 小时前
四叉树:二维空间的 “智能分区管理员”
前端·javascript·计算机图形学
Mintopia2 小时前
Three.js 深度冲突:当像素在 Z 轴上玩起 "挤地铁" 游戏
前端·javascript·three.js
Penk是个码农2 小时前
web前端面试-- MVC、MVP、MVVM 架构模式对比
前端·面试·mvc
MrSkye2 小时前
🔥JavaScript 入门必知:代码如何运行、变量提升与 let/const🔥
前端·javascript·面试
白瓷梅子汤2 小时前
跟着官方示例学习 @tanStack-form --- Linked Fields
前端·react.js