Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
#Falah with Gradio
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
from PIL import Image, ImageDraw
|
@@ -18,14 +17,17 @@ def detect_and_visualize_objects(image):
|
|
18 |
|
19 |
# Draw bounding boxes and labels on the image
|
20 |
draw = ImageDraw.Draw(image)
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
# Return the annotated image
|
31 |
return image
|
@@ -38,8 +40,8 @@ iface = gr.Interface(
|
|
38 |
fn=detect_and_visualize_objects,
|
39 |
inputs=image_input,
|
40 |
outputs=image_output,
|
41 |
-
title="Space and War Missile Detection System
|
42 |
-
description="Detect objects in an image using a pre-trained model and visualize the results."
|
43 |
)
|
44 |
|
45 |
# Launch the Gradio interface
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image, ImageDraw
|
|
|
17 |
|
18 |
# Draw bounding boxes and labels on the image
|
19 |
draw = ImageDraw.Draw(image)
|
20 |
+
if len(predictions) == 0:
|
21 |
+
draw.text((10, 10), "Object not found in image", fill="red")
|
22 |
+
else:
|
23 |
+
for prediction in predictions:
|
24 |
+
box = prediction["box"]
|
25 |
+
label = prediction["label"]
|
26 |
+
score = prediction["score"]
|
27 |
+
|
28 |
+
xmin, ymin, xmax, ymax = box.values()
|
29 |
+
draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=1)
|
30 |
+
draw.text((xmin, ymin), f"{label}: {round(score, 2)}", fill="white")
|
31 |
|
32 |
# Return the annotated image
|
33 |
return image
|
|
|
40 |
fn=detect_and_visualize_objects,
|
41 |
inputs=image_input,
|
42 |
outputs=image_output,
|
43 |
+
title="Space and War Missile Detection System",
|
44 |
+
description="Detect objects in an image using a pre-trained model and visualize the results."
|
45 |
)
|
46 |
|
47 |
# Launch the Gradio interface
|