Spaces:
Runtime error
Runtime error
title: Image Classification | |
emoji: 🔥 | |
colorFrom: green | |
colorTo: red | |
sdk: gradio | |
sdk_version: 3.28.3 | |
app_file: app.py | |
pinned: false | |
license: other | |
duplicated_from: glrh11/image-classification | |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference | |
# 介绍 | |
这段代码创建了一个基于 Gradio 的内窥检测隐患识别接口。 | |
首先导入需要的库,包括 Gradio 和 Transformers。然后,使用 os 库获取环境变量中的 token。 | |
通过调用 pipeline() 函数来加载训练好的模型,使用预设参数 task 表示任务类型,model 参数指定了模型的名称,use_auth_token 参数传递了 token 值,以便进行认证和授权。 | |
接下来定义了一个 predict() 函数,接收一个图片参数,返回预测结果。这个函数内部调用了 pipeline() 函数进行预测,将预测结果转换为字典形式,并返回。 | |
最后使用 Gradio 创建了一个用户界面,其中: | |
gr.inputs.Image() 表示输入组件为图片上传 | |
gr.outputs.Label() 表示输出组件是标签 | |
num_top_classes 参数指定了要显示的标签数量 | |
调用 launch() 函数启动了接口。 |