basilshaji commited on
Commit
dd36fa7
·
verified ·
1 Parent(s): b65c0d7

Delete app11.py

Browse files
Files changed (1) hide show
  1. app11.py +0 -67
app11.py DELETED
@@ -1,67 +0,0 @@
1
- import gradio as gr
2
- import cv2
3
- import requests
4
- import os
5
- import torch
6
- from yolov5.models.experimental import attempt_load
7
- from yolov5.utils.general import non_max_suppression
8
- import yolov5.utils.plots
9
- import yolov5.utils.plots
10
- dir(yolov5.utils.plots)
11
-
12
- file_urls = [
13
- "https://www.dropbox.com/scl/fi/n3bs5xnl2kanqmwv483k3/1_jpg.rf.4a59a63d0a7339d280dd18ef3c2e675a.jpg?rlkey=4n9dnls1byb4wm54ycxzx3ovi&st=ue5xv8yx&dl=0",
14
- "https://www.dropbox.com/scl/fi/asrmao4b4fpsrhqex8kog/2_jpg.rf.b87583d95aa220d4b7b532ae1948e7b7.jpg?rlkey=jkmux5jjy8euzhxizupdmpesb&st=v3ld14tx&dl=0",
15
- "https://www.dropbox.com/scl/fi/fi0e8zxqqy06asnu0robz/3_jpg.rf.d2932cce7e88c2675e300ececf9f1b82.jpg?rlkey=hfdqwxkxetabe38ukzbb39pl5&st=ga1uouhj&dl=0",
16
- "https://www.dropbox.com/scl/fi/ruobyat1ld1c33ch5yjpv/4_jpg.rf.3395c50b4db0ec0ed3448276965b2459.jpg?rlkey=j1m4qa0pmdh3rlr344v82u3am&st=lex8h3qi&dl=0",
17
- "https://www.dropbox.com/scl/fi/ok3izk4jj1pg6psxja3aj/5_jpg.rf.62f3dc64b6c894fbb165d8f6e2ee1382.jpg?rlkey=euu16z8fd8u8za4aflvu5qg4v&st=pwno39nc&dl=0",
18
- "https://www.dropbox.com/scl/fi/8r1fpwxkwq7c2i6ky6qv5/10_jpg.rf.c1785c33dd3552e860bf043c2fd0a379.jpg?rlkey=fcw41ppgzu0ao7xo6ijbpdi4c&st=to2udvxb&dl=0",
19
- "https://www.dropbox.com/scl/fi/ihiid7hbz1vvaoqrstwa5/7_jpg.rf.dfc30f9dc198cf6697d9023ac076e822.jpg?rlkey=yh67p4ex52wn9t0bfw0jr77ef&st=02qw80xa&dl=0",
20
- ]
21
-
22
- def download_file(url, save_name):
23
- if not os.path.exists(save_name):
24
- file = requests.get(url)
25
- open(save_name,'wb').write(file.content)
26
-
27
- # Download files
28
- for i, url in enumerate(file_urls):
29
- if "mp4" in url:
30
- download_file(url, "video.mp4")
31
- else:
32
- download_file(url, f"image_{i}.jpg")
33
-
34
- # Load YOLOv5 model
35
- model_path = "best.pt"
36
- model = attempt_load(model_path, device=torch.device('cpu'))
37
-
38
- def show_preds_image(image_path):
39
- img0 = cv2.imread(image_path) # Open image
40
-
41
- # Inference
42
- results = model(img0) # Pass image to model
43
-
44
- # Process detections
45
- for i, det in enumerate(results.pred[0]):
46
- # Draw bounding boxes
47
- plot_one_box(det.cpu().numpy(), img0, color=(0, 0, 255), line_thickness=2)
48
-
49
- return cv2.cvtColor(img0, cv2.COLOR_BGR2RGB)
50
-
51
- inputs_image = [
52
- gr.inputs.Image(type="file", label="Input Image"),
53
- ]
54
- outputs_image = [
55
- gr.outputs.Image(type="numpy", label="Output Image"),
56
- ]
57
-
58
- interface_image = gr.Interface(
59
- fn=show_preds_image,
60
- inputs=inputs_image,
61
- outputs=outputs_image,
62
- title="YOLOv5 Object Detection",
63
- examples=[["image_0.jpg"], ["image_1.jpg"]],
64
- live=False,
65
- )
66
-
67
- interface_image.launch()