File size: 2,275 Bytes
8d8dfff
9b8057a
8d8dfff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f4fe5ce
8d8dfff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
import cv2
import requests
import os
 
from ultralytics import YOLO
 
file_urls = [
    "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"
]
 
def download_file(url, save_name):
    url = url
    if not os.path.exists(save_name):
        file = requests.get(url)
        open(save_name, 'wb').write(file.content)
 
for i, url in enumerate(file_urls):
    if 'mp4' in file_urls[i]:
        download_file(
            file_urls[i],
            f"video.mp4"
        )
    else:
        download_file(
            file_urls[i],
            f"image_{i}.jpg"
        )
        
model = YOLO('audicar.pt')
path  = [['image_0.jpg'], ['image_1.jpg']]
video_path = [['video.mp4']]


def show_preds_image(image_path):
    image = cv2.imread(image_path)
    outputs = model.predict(source=image_path)
    results = outputs[0].cpu().numpy()
    for i, det in enumerate(results.boxes.xyxy):
        cv2.rectangle(
            image,
            (int(det[0]), int(det[1])),
            (int(det[2]), int(det[3])),
            color=(0, 0, 255),
            thickness=2,
            lineType=cv2.LINE_AA
        )
    return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
 
inputs_image = [
    gr.components.Image(type="filepath", label="Input Image"),
]
outputs_image = [
    gr.components.Image(type="numpy", label="Output Image"),
]
interface_image = gr.Interface(
    fn=show_preds_image,
    inputs=inputs_image,
    outputs=outputs_image,
    title="Pothole detector",
    examples=path,
    cache_examples=False,
)