Spaces:
Sleeping
Sleeping
Add app.py and .pt model
Browse files- app.py +59 -0
- racist2.0.pt +3 -0
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from ultralytics import YOLO
|
4 |
+
|
5 |
+
torch.hub.download_url_to_file(
|
6 |
+
'https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftexashafts.com%2Fwp-content%2Fuploads%2F2016%2F04%2Fconstruction-worker.jpg', 'one.jpg')
|
7 |
+
torch.hub.download_url_to_file(
|
8 |
+
'https://www.pearsonkoutcherlaw.com/wp-content/uploads/2020/06/Construction-Workers.jpg', 'two.jpg')
|
9 |
+
torch.hub.download_url_to_file(
|
10 |
+
'https://nssgroup.com/wp-content/uploads/2019/02/Building-maintenance-blog.jpg', 'three.jpg')
|
11 |
+
|
12 |
+
|
13 |
+
def handle_classify(image: gr.inputs.Image = None):
|
14 |
+
"""This function performs YOLOv8 object detection on the given image.
|
15 |
+
|
16 |
+
Args:
|
17 |
+
image (gr.inputs.Image, optional): Input image to detect objects on. Defaults to None.
|
18 |
+
"""
|
19 |
+
|
20 |
+
model_path = "racist2.0.pt"
|
21 |
+
model = YOLO(model_path)
|
22 |
+
|
23 |
+
results = model(image)
|
24 |
+
|
25 |
+
result = results[0]
|
26 |
+
|
27 |
+
top5 = [[result.names[class_index], result.probs.top5conf.tolist()[rank]]
|
28 |
+
for class_index, rank in zip(result.probs.top5, range(5))]
|
29 |
+
|
30 |
+
print(top5)
|
31 |
+
|
32 |
+
return top5
|
33 |
+
|
34 |
+
|
35 |
+
inputs = [
|
36 |
+
gr.inputs.Image(type="filepath", label="Input Image"),
|
37 |
+
]
|
38 |
+
|
39 |
+
|
40 |
+
outputs = gr.outputs.Text()
|
41 |
+
|
42 |
+
title = "Racist model v2"
|
43 |
+
|
44 |
+
|
45 |
+
examples = [['one.jpg'],
|
46 |
+
['two.jpg'],
|
47 |
+
['three.jpg']]
|
48 |
+
|
49 |
+
yolo_app = gr.Interface(
|
50 |
+
fn=handle_classify,
|
51 |
+
inputs=inputs,
|
52 |
+
outputs=outputs,
|
53 |
+
title=title,
|
54 |
+
examples=examples,
|
55 |
+
cache_examples=True,
|
56 |
+
)
|
57 |
+
|
58 |
+
# Launch the Gradio interface in debug mode with queue enabled
|
59 |
+
yolo_app.launch(debug=True, enable_queue=True)
|
racist2.0.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6c59a98befcac1c90e9500f01516a88ae728eb3cea2a0e13c20d1f42d30efd41
|
3 |
+
size 112503345
|