hiraltalsaniya commited on
Commit
77a49f6
1 Parent(s): a80a97a

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -89
app.py DELETED
@@ -1,89 +0,0 @@
1
- import gradio as gr
2
- import cv2
3
- import requests
4
- import os
5
-
6
- from ultralytics import YOLO
7
-
8
-
9
-
10
- def download_file(url, save_name):
11
- url = url
12
- if not os.path.exists(save_name):
13
- file = requests.get(url)
14
- open(save_name, 'wb').write(file.content)
15
-
16
-
17
- model = YOLO('best.pt')
18
- path = [['image_0.jpg'], ['image_1.jpg']]
19
- video_path = [['video.mp4']]
20
-
21
- def show_preds_image(image_path):
22
- image = cv2.imread(image_path)
23
- outputs = model.predict(source=image_path)
24
- results = outputs[0].cpu().numpy()
25
- for i, det in enumerate(results.boxes.xyxy):
26
- cv2.rectangle(
27
- image,
28
- (int(det[0]), int(det[1])),
29
- (int(det[2]), int(det[3])),
30
- color=(0, 0, 255),
31
- thickness=2,
32
- lineType=cv2.LINE_AA
33
- )
34
- return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
35
-
36
- inputs_image = [
37
- gr.components.Image(type="filepath", label="Input Image"),
38
- ]
39
- outputs_image = [
40
- gr.components.Image(type="numpy", label="Output Image"),
41
- ]
42
- interface_image = gr.Interface(
43
- fn=show_preds_image,
44
- inputs=inputs_image,
45
- outputs=outputs_image,
46
- title="Mask detector app",
47
- examples=path,
48
- cache_examples=False,
49
- )
50
-
51
- def show_preds_video(video_path):
52
- cap = cv2.VideoCapture(video_path)
53
- while(cap.isOpened()):
54
- ret, frame = cap.read()
55
- if ret:
56
- frame_copy = frame.copy()
57
- outputs = model.predict(source=frame)
58
- results = outputs[0].cpu().numpy()
59
- for i, det in enumerate(results.boxes.xyxy):
60
- cv2.rectangle(
61
- frame_copy,
62
- (int(det[0]), int(det[1])),
63
- (int(det[2]), int(det[3])),
64
- color=(0, 0, 255),
65
- thickness=2,
66
- lineType=cv2.LINE_AA
67
- )
68
- yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
69
-
70
- inputs_video = [
71
- gr.components.Video(type="filepath", label="Input Video"),
72
-
73
- ]
74
- outputs_video = [
75
- gr.components.Image(type="numpy", label="Output Image"),
76
- ]
77
- interface_video = gr.Interface(
78
- fn=show_preds_video,
79
- inputs=inputs_video,
80
- outputs=outputs_video,
81
- title="mask detector",
82
- examples=video_path,
83
- cache_examples=False,
84
- )
85
-
86
- gr.TabbedInterface(
87
- [interface_image, interface_video],
88
- tab_names=['Image inference', 'Video inference']
89
- ).queue().launch()