Spaces:
Runtime error
Runtime error
Commit
Β·
dd4d617
1
Parent(s):
6fe0703
Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,70 @@
|
|
1 |
import gradio as gr
|
2 |
-
import cv2
|
3 |
-
import requests
|
4 |
-
import os
|
5 |
import torch
|
6 |
-
from
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
]
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
if not os.path.exists(save_name):
|
18 |
-
file = requests.get(url)
|
19 |
-
open(save_name, 'wb').write(file.content)
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
print('enter the image data')
|
24 |
-
else:
|
25 |
-
download_file(
|
26 |
-
file_urls[i],
|
27 |
-
f"image_{i}.jpg"
|
28 |
-
)
|
29 |
|
30 |
-
|
31 |
-
path = [['image_0.jpg'], ['image_1.jpg']]
|
32 |
|
33 |
-
|
34 |
-
image = cv2.imread(image_path)
|
35 |
-
outputs = model.predict(source=image_path)
|
36 |
-
results = outputs[0].cpu().numpy()
|
37 |
-
for i, det in enumerate(results.boxes.xyxy):
|
38 |
-
cv2.rectangle(
|
39 |
-
image,
|
40 |
-
(int(det[0]), int(det[1])),
|
41 |
-
(int(det[2]), int(det[3])),
|
42 |
-
color=(0, 0, 255),
|
43 |
-
thickness=2,
|
44 |
-
lineType=cv2.LINE_AA
|
45 |
-
)
|
46 |
-
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
)
|
62 |
-
|
63 |
-
[interface_image],
|
64 |
-
tab_names=['Image inference']
|
65 |
-
).queue().launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
import torch
|
3 |
+
from sahi.prediction import ObjectPrediction
|
4 |
+
from sahi.utils.cv import visualize_object_predictions, read_image
|
5 |
+
from ultralyticsplus import YOLO, render_result
|
6 |
|
7 |
+
def yolov8_inference(
|
8 |
+
image: gr.inputs.Image = None,
|
9 |
+
model_path: gr.inputs.Dropdown = None,
|
10 |
+
image_size: gr.inputs.Slider = 640,
|
11 |
+
conf_threshold: gr.inputs.Slider = 0.25,
|
12 |
+
iou_threshold: gr.inputs.Slider = 0.45,
|
13 |
+
):
|
14 |
+
"""
|
15 |
+
YOLOv8 inference function
|
16 |
+
Args:
|
17 |
+
image: Input image
|
18 |
+
model_path: Path to the model
|
19 |
+
image_size: Image size
|
20 |
+
conf_threshold: Confidence threshold
|
21 |
+
iou_threshold: IOU threshold
|
22 |
+
Returns:
|
23 |
+
Rendered image
|
24 |
+
"""
|
25 |
+
model = YOLO(model_path)
|
26 |
+
model.overrides['conf'] = conf_threshold
|
27 |
+
model.overrides['iou']= iou_threshold
|
28 |
+
model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
29 |
+
model.overrides['max_det'] = 1000
|
30 |
+
image = read_image(image)
|
31 |
+
results = model.predict(image)
|
32 |
+
render = render_result(model=model, image=image, result=results[0])
|
33 |
+
|
34 |
+
return render
|
35 |
+
|
36 |
|
37 |
+
inputs = [
|
38 |
+
gr.inputs.Image(type="filepath", label="Input Image"),
|
39 |
+
gr.inputs.Dropdown(["foduucom/thermal-image-object-detection"],
|
40 |
+
default="foduucom/thermal-image-object-detection", label="Model"),
|
41 |
+
gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
|
42 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
|
43 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"),
|
44 |
]
|
45 |
|
46 |
+
outputs = gr.outputs.Image(type="filepath", label="Output Image")
|
47 |
+
title = "ThermalSense: Object Detection in Thermal Images"
|
|
|
|
|
|
|
48 |
|
49 |
+
description ="""
|
50 |
+
Tired of playing 'Where's Waldo?' with your thermal images? Look no further! π΅οΈββοΈπ Our cutting-edge app, powered by the incredible Foduu AI model, has mastered the art of object detection in thermal images. Whether it's locating your lost TV remote in the abyss of your cozy couch or pinpointing the neighborhood cat's stealthy midnight escapades, ThermalFoduu has got your back! π±π₯
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
No more squinting at pixelated blobs β our app skillfully identifies objects with the precision of a hawk eyeing its prey. π¦
π― Worried about distinguishing between a warm pizza slice and your sneaky pet lizard? Worry no more! ThermalFoduu's got your back, even in the most 'heated' culinary conundrums. ππ¦
|
|
|
53 |
|
54 |
+
And if you ever find yourself puzzled by the nuances of thermal imagery or craving a deeper dive into the infrared universe, fear not! Our friendly team at Foduu is just an email away. Contact us at info@foduu for all your questions, suggestions, or even if you just want to chat about the latest trends in thermal fashion. ππ§
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
So, if you're ready to unveil the secrets hidden within thermal landscapes, join the ThermalFoduu revolution today! Tap that download button and let the thermal adventure begin! ππ #ThermalFoduu #HeatSeeker #FoduuMagic
|
57 |
+
|
58 |
+
"""
|
59 |
+
examples = [['samples/1.jpg', 'foduucom/thermal-image-object-detection', 640, 0.25, 0.45], ['samples/2.jpg', 'foduucom/thermal-image-object-detection', 640, 0.25, 0.45]]
|
60 |
+
demo_app = gr.Interface(
|
61 |
+
fn=yolov8_inference,
|
62 |
+
inputs=inputs,
|
63 |
+
outputs=outputs,
|
64 |
+
title=title,
|
65 |
+
description=description,
|
66 |
+
examples=examples,
|
67 |
+
cache_examples=True,
|
68 |
+
theme='huggingface',
|
69 |
)
|
70 |
+
demo_app.launch(debug=True, enable_queue=True)
|
|
|
|
|
|