xfys commited on
Commit
588951f
·
1 Parent(s): 9c303c9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio.inputs
2
+ import torch
3
+ import gradio as gr
4
+ from PIL import Image
5
+ import tempfile
6
+ import detect
7
+ import os
8
+ import shutil
9
+
10
+
11
+ # result = detect.run(source=img, data="VOCdevkit/FLIR.yaml", weights="./best.pt")
12
+
13
+ def de(image):
14
+ # 创建临时文件夹
15
+ temp_path = tempfile.TemporaryDirectory(dir="./")
16
+ temp_dir = temp_path.name
17
+ # 临时图片的路径
18
+ temp_image_path = os.path.join(temp_dir, f"temp.jpg")
19
+ # 存储临时图片
20
+ img = Image.fromarray(image)
21
+ img.save(temp_image_path)
22
+ # 结果图片的存储目录
23
+ temp_result_path = os.path.join(temp_dir, "tempresult")
24
+ # 对临时图片进行检测
25
+ detect.run(source=temp_image_path, data="OCdevkit/FLIR.yaml", weights="./runs/train/exp/weights/best.pt", project=f'./{temp_dir}',name = 'tempresult', hide_conf=True)
26
+ # 结果图片的路径
27
+ temp_result_path = os.path.join(temp_result_path, os.listdir(temp_result_path)[0])
28
+ # 读取结果图片
29
+ result_image = Image.open(temp_result_path).copy()
30
+ # 删除临时文件夹
31
+ temp_path.cleanup()
32
+
33
+ return result_image
34
+
35
+ example_image= [
36
+ ["./VOCdevkit/images/train/video-2SReBn5LtAkL5HMj2-frame-005072-MA7NCLQGoqq9aHaiL.jpg"],
37
+ ["./VOCdevkit/images/train/video-2rsjnZFyGQGeynfbv-frame-003708-6fPQbB7jtibwaYAE7.jpg"],
38
+ ["./VOCdevkit/images/train/video-2SReBn5LtAkL5HMj2-frame-000317-HTgPBFgZyPdwQnNvE.jpg"],
39
+ ["./VOCdevkit/images/val/video-jNQtRj6NGycZDEXpe-frame-002515-J3YntG8ntvZheKK3P.jpg"],
40
+ ["./VOCdevkit/images/val/video-kDDWXrnLSoSdHCZ7S-frame-003063-eaKjPvPskDPjenZ8S.jpg"],
41
+ ["./VOCdevkit/images/val/video-r68Yr9RPWEp5fW2ZF-frame-000333-X6K5iopqbmjKEsSqN.jpg"]
42
+ ]
43
+
44
+ iface = gr.Interface(fn=de, inputs=gr.Image(label="上传一张红外图像,仅支持jpg格式"), outputs="image", examples=example_image, share=True)
45
+ iface.launch(share=True)
46
+
47
+
48
+
49
+
50
+