AIGC之gradio系列学习教程(一)

演示或 Web 应用程序。然后,您可以使用 Gradio 的内置共享功能在短短几秒钟内共享演示或 Web 应用程序的链接。Gradio 是一个开源 Python 包,可让快速为机器学习模型、API 或任何任意 Python 函数。无需 JavaScript、CSS 或网络托管能力!主题:本篇即为入门,后续将会从函数和使用场景介绍。
摘要由CSDN通过智能技术生成

主题:本篇即为入门,后续将会从函数和使用场景介绍。

Gradio 是一个开源 Python 包,可让快速为机器学习模型、API 或任何任意 Python 函数构建演示或 Web 应用程序。然后,您可以使用 Gradio 的内置共享功能在短短几秒钟内共享演示或 Web 应用程序的链接无需 JavaScript、CSS 或网络托管能力!

准备:

1. python 3.8+

2.安装:

pip install gradio

示例1:

import gradio as gr

def greet(name, intensity):
    return "Hello, " + name + "!" * int(intensity)

demo = gr.Interface(
    fn=greet,
    inputs=["text", "slider"],
    outputs=["text"],
)

demo.launch()

运行如下:

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个自定义的样式,它将输入和输出放在一个圆角矩形框中,并将标题和输入、输出标签放在不同的颜色条中: ``` import gradio as gr def greet(name): return "Hello, " + name + "!" iface = gr.Interface(fn=greet, inputs="text", outputs="text", title="Greeting", layout="custom", inputs_layout="vertical", outputs_layout="vertical", input_container="card", output_container="card", input_label=None, output_label=None, input_description=None, output_description=None, input_width=350, output_width=350, examples=[["Alice"], ["Bob"], ["Charlie"]], theme="light", custom_css=""".input-container.card { border-radius: 10px; padding: 20px; background-color: #f3f3f3; margin-bottom: 20px; } .output-container.card { border-radius: 10px; padding: 20px; background-color: #f3f3f3; } .inputs-title { background-color: #95c3e4; color: white; border-radius: 10px 10px 0px 0px; padding: 10px; margin-bottom: 10px; } .outputs-title { background-color: #95c3e4; color: white; border-radius: 0px 0px 10px 10px; padding: 10px; margin-top: 20px; margin-bottom: 10px; }""") iface.launch() ``` 在这个例子中,我们使用了 "custom" 样式,并通过指定不同的参数来自定义布局和样式。具体的自定义内容如下: 1. `inputs_layout="vertical"` 和 `outputs_layout="vertical"`:将输入和输出垂直排列。 2. `input_container="card"` 和 `output_container="card"`:将输入和输出放在圆角矩形框中。 3. `input_label=None` 和 `output_label=None`:不显示输入和输出的标签。 4. `input_description=None` 和 `output_description=None`:不显示输入和输出的描述。 5. `input_width=350` 和 `output_width=350`:指定输入和输出的宽度为 350 像素。 6. `examples=[["Alice"], ["Bob"], ["Charlie"]]`:在输入框中提供一些示例字符串。 7. `theme="light"`:使用浅色主题。 8. `custom_css`:自定义 CSS 样式,将输入和输出的圆角矩形框和标题分别设置为不同的背景颜色。 你可以在运行上述代码后,尝试在输入框中输入你的名字来查看效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值