Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,30 +20,22 @@ class_names = {0: "Dumbbell", 1: "Kettlebell"} # Adjust based on your dataset
|
|
20 |
|
21 |
# Define prediction function
|
22 |
def predict(image):
|
23 |
-
# Perform inference
|
24 |
-
results = model.predict(image
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
# Restrict to trained classes
|
37 |
-
if class_idx < len(class_names): # Ensure index is valid
|
38 |
-
detections.append({
|
39 |
-
"class": class_names[class_idx], # Use the mapped class name
|
40 |
-
"confidence": confidence,
|
41 |
-
"bbox": bbox
|
42 |
-
})
|
43 |
|
44 |
return output_image, detections
|
45 |
|
46 |
-
|
47 |
# Create Gradio interface
|
48 |
interface = gr.Interface(
|
49 |
fn=predict,
|
|
|
20 |
|
21 |
# Define prediction function
|
22 |
def predict(image):
|
23 |
+
# Perform inference
|
24 |
+
results = model.predict(image)
|
25 |
+
output_image = results[0].plot() # Annotated image with predictions
|
26 |
+
|
27 |
+
# Prepare detection details
|
28 |
+
detections = [
|
29 |
+
{
|
30 |
+
"class": class_names.get(int(result.cls), "Unknown"), # Map class index to name
|
31 |
+
"confidence": float(result.conf),
|
32 |
+
"bbox": result.xyxy.tolist(),
|
33 |
+
}
|
34 |
+
for result in results[0].boxes
|
35 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
return output_image, detections
|
38 |
|
|
|
39 |
# Create Gradio interface
|
40 |
interface = gr.Interface(
|
41 |
fn=predict,
|