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 小时前
如何实现流式输出?一篇文章手把手教你!
前端·aigc·ai编程
前端 贾公子1 小时前
vue移动端适配方案 === postcss-px-to-viewport
前端·javascript·html
GISer_Jing2 小时前
AI营销增长:4大核心能力+前端落地指南
前端·javascript·人工智能
明远湖之鱼3 小时前
一种基于 Service Worker 的渐进式渲染方案的基本原理
前端
前端小端长3 小时前
Vue 中 keep-alive 组件的原理与实践详解
前端·vue.js·spring
FeelTouch Labs4 小时前
Nginx核心架构设计
运维·前端·nginx
雪球工程师团队4 小时前
别再“苦力”写后台,Spec Coding “跑” 起来
前端·ai编程
m0_471199634 小时前
【场景】前端怎么解决离线收银、数据同步异常等场景问题
前端·javascript
Curvatureflight4 小时前
前端性能优化实战:从3秒到300ms的加载速度提升
前端·人工智能·性能优化