Spaces:
Runtime error
Runtime error
Car detector app
Browse files- app.py +63 -0
- audicar.pt +3 -0
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import requests
|
4 |
+
import os
|
5 |
+
|
6 |
+
from ultralytics import YOLO
|
7 |
+
|
8 |
+
file_urls = [
|
9 |
+
"https://www.bing.com/images/search?view=detailV2&ccid=YaFiK%2bN6&id=D84622E2396A39F168D279F32AC31F05096187AB&thid=OIP.YaFiK-N6iDdJR6B6DMBHpgHaFj&mediaurl=https%3a%2f%2fwww.practicalcaravan.com%2fwp-content%2fuploads%2f2016%2f03%2f5907569-scaled.jpg&exph=1921&expw=2560&q=audi+a4+car+image&simid=608053806389945942&FORM=IRPRST&ck=7DDB4BC7AA27F8E3EDA4433E669D3CC4&selectedIndex=6&ajaxhist=0&ajaxserp=0","https://www.bing.com/images/search?view=detailV2&ccid=CHONQxwQ&id=B8BCD1A5420658017C772CF149AFB7D24F2F8322&thid=OIP.CHONQxwQrclsFp-VXh4aOQHaFD&mediaurl=https%3a%2f%2fs3-eu-west-1.amazonaws.com%2feurekar-v2%2fuploads%2fimages%2foriginal%2fa4salfront.jpg&exph=1025&expw=1500&q=audi+a4+car+image&simid=608024308599848180&FORM=IRPRST&ck=3A2EA226332024ECB13B2F27682C15CA&selectedIndex=3&ajaxhist=0&ajaxserp=0"
|
10 |
+
]
|
11 |
+
|
12 |
+
def download_file(url, save_name):
|
13 |
+
url = url
|
14 |
+
if not os.path.exists(save_name):
|
15 |
+
file = requests.get(url)
|
16 |
+
open(save_name, 'wb').write(file.content)
|
17 |
+
|
18 |
+
for i, url in enumerate(file_urls):
|
19 |
+
if 'mp4' in file_urls[i]:
|
20 |
+
download_file(
|
21 |
+
file_urls[i],
|
22 |
+
f"video.mp4"
|
23 |
+
)
|
24 |
+
else:
|
25 |
+
download_file(
|
26 |
+
file_urls[i],
|
27 |
+
f"image_{i}.jpg"
|
28 |
+
)
|
29 |
+
|
30 |
+
model = YOLO('audicar.pt')
|
31 |
+
path = [['image_0.jpg'], ['image_1.jpg']]
|
32 |
+
video_path = [['video.mp4']]
|
33 |
+
|
34 |
+
|
35 |
+
def show_preds_image(image_path):
|
36 |
+
image = cv2.imread(image_path)
|
37 |
+
outputs = model.predict(source=image_path)
|
38 |
+
results = outputs[0].cpu().numpy()
|
39 |
+
for i, det in enumerate(results.boxes.xyxy):
|
40 |
+
cv2.rectangle(
|
41 |
+
image,
|
42 |
+
(int(det[0]), int(det[1])),
|
43 |
+
(int(det[2]), int(det[3])),
|
44 |
+
color=(0, 0, 255),
|
45 |
+
thickness=2,
|
46 |
+
lineType=cv2.LINE_AA
|
47 |
+
)
|
48 |
+
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
49 |
+
|
50 |
+
inputs_image = [
|
51 |
+
gr.components.Image(type="filepath", label="Input Image"),
|
52 |
+
]
|
53 |
+
outputs_image = [
|
54 |
+
gr.components.Image(type="numpy", label="Output Image"),
|
55 |
+
]
|
56 |
+
interface_image = gr.Interface(
|
57 |
+
fn=show_preds_image,
|
58 |
+
inputs=inputs_image,
|
59 |
+
outputs=outputs_image,
|
60 |
+
title="Pothole detector",
|
61 |
+
examples=path,
|
62 |
+
cache_examples=False,
|
63 |
+
)
|
audicar.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c432d9ff87954cddb8a05e3f4204e56b1c01c3cb60fd328e3532d1dc91e3dcac
|
3 |
+
size 6772738
|