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 小时前
不引 Ghostscript:我用纯 Go 给 PDF 做了一场「压缩手术」
前端·后端·github
变与不变8068 小时前
jQuery细节以及使用应用场景
前端·javascript·jquery
SailingCoder9 小时前
【封闭结束1】端到端交付:Agent 一次请求如何走完全链路
前端·安全·ai·面试·agent·harness
风骏时光牛马11 小时前
AI多模块协同自动化工作流
前端
zhangminghuan12 小时前
前端面试应对技巧
前端·面试·职场和发展
计算机魔术师12 小时前
潜伏14年的PHP致命洞,AI跑两天就交卷了
前端
IT_陈寒12 小时前
Vue的这个响应式陷阱我居然现在才发现
前端·人工智能·后端
Python自动化直播13 小时前
智能脚本批量管理拆开看:导入、导出、重写、试听
前端·python·ai·秒播
开开心心就好13 小时前
发票信息录入太麻烦?离线工具一键转表格
运维·服务器·前端·pdf·ocr·maven·intellij-idea