Spaces:
No application file
No application file
alicenkbaytop
commited on
Commit
•
b2141e9
1
Parent(s):
a46aabc
app.py, model, image added!
Browse files- app..py +54 -0
- best.pt +3 -0
- duck23.jpeg +0 -0
app..py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.dropbox.com/scl/fi/2mlc191y9lzbe8nwu45ss/duck76.jpeg?rlkey=qwnr78mtdy7sjg71ldrui6vf0&dl=0",
|
10 |
+
"https://www.dropbox.com/scl/fi/2y4cdkwwn3drlh4ob86ic/duck85.jpeg?rlkey=lcl3n0jav7ougsj4tamm1hh93&dl=0",
|
11 |
+
"https://www.dropbox.com/scl/fi/8gojxnm8wwhs2isj6k4zv/duck23.jpeg?rlkey=2zioinhr0wfpv22qq963tnv8a&dl=0",
|
12 |
+
]
|
13 |
+
|
14 |
+
def download_file(url, save_name):
|
15 |
+
if not os.path.exists(save_name):
|
16 |
+
file = requests.get(url)
|
17 |
+
open(save_name, "wb").write(file.content)
|
18 |
+
|
19 |
+
for i, url in enumerate(file_urls):
|
20 |
+
if "mp4" in url:
|
21 |
+
download_file(url, "video.mp4")
|
22 |
+
else:
|
23 |
+
download_file(url, f"image_{i}.jpg")
|
24 |
+
|
25 |
+
model = YOLO("best.pt")
|
26 |
+
|
27 |
+
def show_preds_image(image):
|
28 |
+
outputs = model.predict(source=image)
|
29 |
+
image_np = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
30 |
+
results = outputs.xyxy[0].cpu().numpy()
|
31 |
+
|
32 |
+
for det in results:
|
33 |
+
cv2.rectangle(
|
34 |
+
image_np,
|
35 |
+
(int(det[0]), int(det[1])),
|
36 |
+
(int(det[2]), int(det[3])),
|
37 |
+
color=(0, 0, 255),
|
38 |
+
thickness=2,
|
39 |
+
lineType=cv2.LINE_AA,
|
40 |
+
)
|
41 |
+
return cv2.cvtColor(image_np, cv2.COLOR_BGR2RGB)
|
42 |
+
|
43 |
+
inputs_image = gr.inputs.Image(type="file", label="Input Image")
|
44 |
+
outputs_image = gr.outputs.Image(type="numpy", label="Output Image")
|
45 |
+
interface_image = gr.Interface(
|
46 |
+
fn=show_preds_image,
|
47 |
+
inputs=inputs_image,
|
48 |
+
outputs=outputs_image,
|
49 |
+
title="Duck Image Segmentation",
|
50 |
+
examples=file_urls,
|
51 |
+
allow_flagging=False,
|
52 |
+
)
|
53 |
+
|
54 |
+
interface_image.launch()
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b71d65569e7091a1bd20581881c6709d6312db127c33131fd89dcaf3bd091cdc
|
3 |
+
size 6788323
|
duck23.jpeg
ADDED