Spaces:
Runtime error
Runtime error
File size: 805 Bytes
f8633e2 aeb618e 6468d44 f8633e2 e205ba6 aeb618e f8633e2 e205ba6 f8633e2 aeb618e f8633e2 aeb618e f8633e2 7dd2efb f8633e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 导入所需库
import gradio as gr
from transformers import pipeline
import os
# 获取环境变量中的token
drainage_token = os.environ.get("drainage_token")
# 加载预训练模型
pipeline = pipeline(task="image-classification", model="zijia88/autotrain-drainage-56552131498", use_auth_token=drainage_token)
# 预测函数,输入图片,返回预测结果
def predict(image):
predictions = pipeline(image)
return {p["label"]: p["score"] for p in predictions}
# 创建Gradio接口
gr.Interface(
predict, # 预测函数
inputs=gr.inputs.Image(label="上传管道内窥检测图片", type="filepath"), # 图片上传输入组件
outputs=gr.outputs.Label(num_top_classes=5), # 标签输出组件
title="内窥检测隐患识别", # 接口标题
).launch() # 启动接口 |