mohotta commited on
Commit
8cdfe75
·
1 Parent(s): 45686b9

chatgpt code

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +24 -2
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ conda-env/
app.py CHANGED
@@ -4,10 +4,32 @@ from ultralytics import YOLO
4
  import cv2
5
 
6
  def segment(input_img):
 
7
  model = YOLO('model.pt')
 
 
8
  result = model(input_img, conf=0.1)
9
- return result[0].plot()
10
 
11
- demo = gr.Interface(segment, gr.Image(), "image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  if __name__ == "__main__":
13
  demo.launch()
 
4
  import cv2
5
 
6
  def segment(input_img):
7
+ # Load the YOLO model
8
  model = YOLO('model.pt')
9
+
10
+ # Perform segmentation
11
  result = model(input_img, conf=0.1)
 
12
 
13
+ # Get the plot of the result
14
+ img_with_results = result[0].plot()
15
+
16
+ # Extract class names and confidences
17
+ confidences = []
18
+ for res in result:
19
+ for det in res:
20
+ conf = det.conf.item() # Get confidence of detection
21
+ label = det.cls # Get class label (index)
22
+ label_name = model.names[int(label)] # Get class name using the label index
23
+ confidences.append(f"{label_name}: {conf:.2f}") # Store formatted class name and confidence
24
+
25
+ return img_with_results, confidences
26
+
27
+ # Create a Gradio Interface with an additional output for confidences
28
+ demo = gr.Interface(
29
+ fn=segment,
30
+ inputs=gr.Image(),
31
+ outputs=[gr.Image(), gr.JSON(label="Class Confidences")]
32
+ )
33
+
34
  if __name__ == "__main__":
35
  demo.launch()