Transformers 文档
机器学习应用
加入 Hugging Face 社区
并获得增强的文档体验
开始使用
机器学习应用
Gradio 是一个用于构建和共享机器学习应用的快速简便的库,它与 Pipeline 集成,可以快速创建简单的推理界面。
在开始之前,请确保已安装 Gradio。
!pip install gradio
为您的任务创建一个管道,然后将其传递给 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 上更新