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)
相关推荐
茶卡盐佑星_19 分钟前
webpack/vite的区别
前端·webpack·node.js
风清扬_jd38 分钟前
Chromium 中前端HTMLDialogElement <Dialog> c++代码实现
开发语言·前端·c++·chrome
黄毛火烧雪下39 分钟前
HTML 常用的块级元素和行内元素
前端·css·html
厉害坤坤1 小时前
前端Vue3字体优化三部曲(webFont、font-spider、spa-font-spider-webpack-plugin)
前端·webpack·node.js
ygming1 小时前
【二分查找】典型题
前端·算法
源心锁2 小时前
🦀 用五天时间把一个百星项目用 Rust 重构,性能真的提升了 25 倍!
前端·性能优化·rust
黄毛火烧雪下2 小时前
HTML 什么是块级元素?
前端·chrome·html
OpenTiny社区2 小时前
【PPT】TinyEngine 低代码引擎系列课第三讲课件分享
前端·javascript·低代码
冰淇淋加点糖2 小时前
C语言之扫雷小游戏(完整代码版)
c语言·前端·算法