elefantphoot commited on
Commit
cae2905
·
verified ·
1 Parent(s): 3998cb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
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 with a higher confidence threshold
24
- results = model.predict(image, conf=0.5) # Set confidence threshold
25
-
26
- # Annotate the output image
27
- output_image = results[0].plot()
28
-
29
- # Filter and prepare detection details
30
- detections = []
31
- for result in results[0].boxes:
32
- class_idx = int(result.cls)
33
- confidence = float(result.conf)
34
- bbox = result.xyxy.tolist()
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,