# 机器学习应用

[Gradio](https://www.gradio.app/) 是一个用于快速构建和共享机器学习应用的便捷库，它与 [Pipeline](/docs/transformers/main/zh/main_classes/pipelines#transformers.Pipeline) 集成，可快速为推理创建简单的界面。

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

```py
!pip install gradio
```

为你的任务创建一个 pipeline，然后将其传递给 Gradio 的 [Interface.from_pipeline](https://www.gradio.app/docs/gradio/interface#interface-from_pipeline) 函数以创建界面。Gradio 会自动为 [Pipeline](/docs/transformers/main/zh/main_classes/pipelines#transformers.Pipeline) 确定合适的输入和输出组件。

添加 [launch](https://www.gradio.app/main/docs/gradio/blocks#blocks-launch) 以创建 Web 服务器并启动应用。

```py
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](https://www.gradio.app/main/docs/gradio/blocks#blocks-launch) 中设置 `share=True` 以生成一个临时的公开链接。如需更持久的方案，可将应用托管在 Hugging Face [Spaces](https://hf.co/spaces) 上。

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

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

<iframe src="https://stevhliu-gradio-pipeline-demo.hf.space" frameborder="0" width="850" height="850"
>

