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)
相关推荐
学历真的很重要7 分钟前
VsCode+Roo Code+Gemini 2.5 Pro+Gemini Balance AI辅助编程环境搭建(理论上通过多个Api Key负载均衡达到无限免费Gemini 2.5 Pro)
前端·人工智能·vscode·后端·语言模型·负载均衡·ai编程
用户47949283569151 小时前
"讲讲原型链" —— 面试官最爱问的 JavaScript 基础
前端·javascript·面试
用户47949283569151 小时前
2025 年 TC39 都在忙什么?Import Bytes、Iterator Chunking 来了
前端·javascript·面试
大怪v2 小时前
【Virtual World 04】我们的目标,无限宇宙!!
前端·javascript·代码规范
狂炫冰美式3 小时前
不谈技术,搞点文化 🧀 —— 从复活一句明代残诗破局产品迭代
前端·人工智能·后端
xw53 小时前
npm几个实用命令
前端·npm
!win !3 小时前
npm几个实用命令
前端·npm
代码狂想家3 小时前
使用openEuler从零构建用户管理系统Web应用平台
前端
dorisrv5 小时前
优雅的React表单状态管理
前端
蓝瑟5 小时前
告别重复造轮子!业务组件多场景复用实战指南
前端·javascript·设计模式