zijia88 commited on
Commit
f8633e2
·
1 Parent(s): 6468d44

Update app.py

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