You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改gr.Interface创建的文本框属性?以autoscroll为例

修改Gradio输出文本框属性的方法

在你的基础gr.Interface示例中,直接用outputs="text"是Gradio提供的快捷方式,会创建默认配置的文本框。如果需要修改比如autoscroll这类属性,你需要显式使用gr.Textbox组件来定义输出,而非用字符串快捷方式。

修改后的完整代码

import gradio as gr

def greet(name):
    return "Hello " + name + "!"

# 显式创建Textbox组件,设置autoscroll为False
demo = gr.Interface(
    fn=greet,
    inputs="text",
    outputs=gr.Textbox(autoscroll=False)  # 替换为自定义配置的Textbox
)

demo.launch()

额外自定义选项

除了autoscroll,你还可以通过gr.Textbox的参数调整其他属性,比如:

  • label: 设置输出框的显示标签,比如label="问候结果"
  • placeholder: 设置输入提示文本
  • lines: 设置文本框的初始行数
  • max_lines: 设置文本框可展开的最大行数

示例:

outputs=gr.Textbox(
    autoscroll=False,
    label="你的问候语",
    lines=3,
    max_lines=10
)

内容的提问来源于stack exchange,提问作者Franck Dernoncourt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 15:12:33