llzzyy233 commited on
Commit
ca99129
1 Parent(s): f63fdc2

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from PIL import Image
4
+ from ultralytics import YOLO
5
+
6
+ model = YOLO(r'pcb-best.pt')
7
+
8
+ def predict(img, conf, iou):
9
+ results = model.predict(img, conf=conf, iou=iou)
10
+ for i, r in enumerate(results):
11
+ # Plot results image
12
+ im_bgr = r.plot() # BGR-order numpy array
13
+ im_rgb = Image.fromarray(im_bgr[..., ::-1]) # RGB-order PIL image
14
+
15
+ # Show results to screen (in supported environments)
16
+ return im_rgb
17
+
18
+
19
+ base_conf, base_iou = 0.25, 0.45
20
+ title = "基于YOLO-V8的PCB电路板缺陷检测"
21
+ des = "鼠标点击上传图片即可检测缺陷,可通过鼠标调整预测置信度,还可点击网页最下方示例图片进行预测"
22
+ gr.Interface(inputs=['image',gr.Slider(maximum=1, minimum=0, value=base_conf), gr.Slider(maximum=1, minimum=0, value=base_iou)],
23
+ outputs=["image"], examples='example1.jpg', fn=predict, title=title, description=des).launch()
24
+