vishalkatheriya18 commited on
Commit
9aaac5d
·
verified ·
1 Parent(s): 199e804

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -15,18 +15,15 @@ def predict_with_yolo(image):
15
  # Run inference on the image using the YOLO model
16
  results = st.session_state.yolo_model(image)
17
 
18
- # Extract predictions
19
- predictions = []
20
  if results:
 
21
  for result in results:
22
- for box in result.boxes:
23
- class_name = result.names[box.label]
24
- confidence = box.conf.item() # Convert tensor to a Python float
25
- predictions.append({
26
- "Class": class_name,
27
- "Confidence": confidence
28
- })
29
- return predictions
30
 
31
  # Streamlit app UI
32
  st.title("Clothing Detection with YOLO")
@@ -46,9 +43,7 @@ if url:
46
 
47
  # Display predictions
48
  if predictions:
49
- st.write("Predictions:")
50
- for pred in predictions:
51
- st.write(f"Class: {pred['Class']}, Confidence: {pred['Confidence']:.2f}")
52
  else:
53
  st.write("No objects detected.")
54
 
 
15
  # Run inference on the image using the YOLO model
16
  results = st.session_state.yolo_model(image)
17
 
18
+ # Print the classification results
 
19
  if results:
20
+ # YOLOv8 classification results contain label and confidence for the whole image
21
  for result in results:
22
+ # print(f"Class: {result.names[result.probs.top1]}, Confidence: {result.probs.top1conf:.2f}")
23
+ return {"Class":result.names[result.probs.top1],"Confidence":result.probs.top1conf:.2f}
24
+ else:
25
+ print("No classification results found.")
26
+
 
 
 
27
 
28
  # Streamlit app UI
29
  st.title("Clothing Detection with YOLO")
 
43
 
44
  # Display predictions
45
  if predictions:
46
+ st.write("Predictions:",predictions)
 
 
47
  else:
48
  st.write("No objects detected.")
49