Transformers 文档

机器学习应用

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

机器学习应用

Gradio,一个快速且易于使用的库,用于构建和共享机器学习应用程序,已与 Pipeline 集成,可快速为推理创建简单的界面。

在开始之前,请确保已安装 Gradio。

!pip install gradio

为你的任务创建一个 pipeline,然后将其传递给 Gradio 的 Interface.from_pipeline 函数以创建界面。Gradio 会自动确定 Pipeline 的适当输入和输出组件。

添加 launch 以创建 Web 服务器并启动应用程序。

from transformers import pipeline
import gradio as gr

pipeline = pipeline("image-classification", model="google/vit-base-patch16-224")
gr.Interface.from_pipeline(pipeline).launch()

Web 应用程序默认在本地服务器上运行。要与其他用户共享应用程序,请在 launch 中设置 share=True 以生成临时公共链接。为了获得更持久的解决方案,请将应用程序托管在 Hugging Face Spaces 上。

gr.Interface.from_pipeline(pipeline).launch(share=True)

下面的 Space 是使用上面的代码创建并在 Spaces 上托管的。

< > 在 GitHub 上更新