Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,16 +18,88 @@ def run_inference(image):
|
|
18 |
annotated_image = results.render()[0]
|
19 |
annotated_image = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Create the Gradio interface
|
24 |
-
interface = gr.
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
annotated_image = results.render()[0]
|
19 |
annotated_image = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
|
20 |
|
21 |
+
# Generate a summary of detected objects
|
22 |
+
detected_objects = results.pandas().xyxy[0]['name'].value_counts().to_dict()
|
23 |
+
summary = "Detected Objects:\n" + "\n".join(
|
24 |
+
[f"{obj}: {count}" for obj, count in detected_objects.items()]
|
25 |
+
)
|
26 |
+
return annotated_image, summary
|
27 |
|
28 |
# Create the Gradio interface
|
29 |
+
interface = gr.Blocks(css="""
|
30 |
+
body {
|
31 |
+
font-family: 'Poppins', sans-serif;
|
32 |
+
background: linear-gradient(135deg, #6a11cb, #2575fc);
|
33 |
+
color: #fff;
|
34 |
+
margin: 0;
|
35 |
+
padding: 0;
|
36 |
+
}
|
37 |
+
|
38 |
+
header {
|
39 |
+
text-align: center;
|
40 |
+
background: linear-gradient(90deg, #ff758c, #ff7eb3);
|
41 |
+
padding: 1rem;
|
42 |
+
border-radius: 15px;
|
43 |
+
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.2);
|
44 |
+
margin-bottom: 1rem;
|
45 |
+
}
|
46 |
+
|
47 |
+
header h1 {
|
48 |
+
margin: 0;
|
49 |
+
font-size: 2.5rem;
|
50 |
+
color: #fff;
|
51 |
+
}
|
52 |
+
|
53 |
+
.description {
|
54 |
+
text-align: center;
|
55 |
+
font-size: 1.2rem;
|
56 |
+
margin: 0.5rem 0 1.5rem 0;
|
57 |
+
color: #f0f0f0;
|
58 |
+
}
|
59 |
+
|
60 |
+
button {
|
61 |
+
background: linear-gradient(90deg, #6a11cb, #2575fc);
|
62 |
+
border: none;
|
63 |
+
border-radius: 10px;
|
64 |
+
padding: 0.8rem 1.5rem;
|
65 |
+
font-size: 1rem;
|
66 |
+
color: white;
|
67 |
+
cursor: pointer;
|
68 |
+
transition: transform 0.2s, background 0.2s;
|
69 |
+
}
|
70 |
+
|
71 |
+
button:hover {
|
72 |
+
transform: scale(1.05);
|
73 |
+
background: linear-gradient(90deg, #2575fc, #6a11cb);
|
74 |
+
}
|
75 |
+
""")
|
76 |
+
|
77 |
+
with interface:
|
78 |
+
with gr.Row():
|
79 |
+
gr.Markdown("<header><h1>🌟 InsightVision: Detect, Analyze, Summarize 🌟</h1></header>")
|
80 |
+
with gr.Row():
|
81 |
+
gr.Markdown(
|
82 |
+
"<div class='description'>Upload an image to detect objects using YOLOv5 and receive a detailed summary of detected items!</div>"
|
83 |
+
)
|
84 |
+
with gr.Row():
|
85 |
+
with gr.Column():
|
86 |
+
uploaded_image = gr.Image(type="pil", label="Upload Your Image")
|
87 |
+
with gr.Column():
|
88 |
+
detected_image = gr.Image(type="pil", label="Detected Objects")
|
89 |
+
summary_output = gr.Textbox(lines=10, label="Summary of Detected Objects")
|
90 |
+
|
91 |
+
with gr.Row():
|
92 |
+
submit_button = gr.Button("Analyze Image")
|
93 |
+
|
94 |
+
def process_image(image):
|
95 |
+
annotated_image, summary = run_inference(image)
|
96 |
+
return annotated_image, summary
|
97 |
+
|
98 |
+
submit_button.click(
|
99 |
+
process_image,
|
100 |
+
inputs=[uploaded_image],
|
101 |
+
outputs=[detected_image, summary_output],
|
102 |
+
)
|
103 |
+
|
104 |
+
if __name__ == "__main__":
|
105 |
+
interface.launch()
|