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)
相关推荐
芯芯点灯1 小时前
gd32f303烧录提示Flash Timeout. Reset the Target and try it again.;
开发语言·前端·javascript
前端若水1 小时前
自定义消息组件:图片、文件附件与图表
前端·人工智能·react.js·typescript
2601_958492551 小时前
7 Best WordPress Tools to Help Your News Site Actually Make Money
前端·word
放下华子我只抽RuiKe51 小时前
React 从入门到生产(七):性能优化实战
前端·javascript·人工智能·react.js·性能优化·前端框架·github
糯米团子7491 小时前
vue知识点复习
前端·vue.js
晚烛1 小时前
CANN 日志系统:调试与性能分析的日志艺术
前端·chrome·数据挖掘
FlyWIHTSKY1 小时前
Next中引入 Ant Design (antd)的配置
开发语言·前端·javascript
JAVA学习通1 小时前
《大营销平台系统设计实现》 - 营销服务 第9节:模板模式串联抽奖规则
服务器·前端·javascript
阿正的梦工坊1 小时前
【Typescript】10-条件类型与-infer
前端·javascript·typescript
GuWenyue2 小时前
我被 React 性能问题逼疯了,直到学会这 4 个优化技巧
前端