# 機械学習アプリ

機械学習アプリの構築と共有を迅速かつ容易に行うためのライブラリである[Gradio](https://www.gradio.app/)は、[Pipeline](/docs/transformers/v5.24.1/ja/main_classes/pipelines#transformers.Pipeline)と統合されており、推論用のシンプルなインターフェースを素早く作成できます。

開始する前に、Gradioがインストールされていることを確認してください。

```py
!pip install gradio
```

Create a pipeline for your task, and then pass it to Gradio's [Interface.from_pipeline](https://www.gradio.app/docs/gradio/interface#interface-from_pipeline) function to create the interface. Gradio automatically determines the appropriate input and output components for a [Pipeline](/docs/transformers/v5.24.1/ja/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"
>

