muskangoyal06 commited on
Commit
169781f
Β·
verified Β·
1 Parent(s): f305096

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -3,15 +3,15 @@ from ultralyticsplus import YOLO, render_result
3
  import cv2
4
  import time
5
 
6
- # Load model with automatic device detection
7
  model = YOLO('foduucom/plant-leaf-detection-and-classification')
8
 
9
- # Optimize model configuration
10
  model.overrides.update({
11
  'conf': 0.25,
12
  'iou': 0.45,
13
  'imgsz': 640,
14
- 'device': '0' if model.device.type != 'cpu' else 'cpu'
15
  })
16
 
17
  def detect_leaves(image):
@@ -20,21 +20,17 @@ def detect_leaves(image):
20
  # Convert image format
21
  img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
22
 
23
- # Predict with optimized settings
24
- results = model.predict(
25
- source=img,
26
- verbose=False, # Disable unnecessary logging
27
- stream=False # Disable streaming mode
28
- )
29
 
30
  # Process results
31
  num_leaves = len(results[0].boxes)
32
  rendered_img = render_result(model=model, image=img, result=results[0])
33
 
34
- print(f"Total processing time: {time.time() - start_time:.2f}s")
35
  return cv2.cvtColor(rendered_img, cv2.COLOR_BGR2RGB), num_leaves
36
 
37
- # Create lightweight interface
38
  interface = gr.Interface(
39
  fn=detect_leaves,
40
  inputs=gr.Image(label="Plant Image"),
@@ -43,12 +39,12 @@ interface = gr.Interface(
43
  gr.Number(label="Leaves Count")
44
  ],
45
  title="πŸƒ Leaf Detection",
46
- allow_flagging="never"
47
  )
48
 
49
  if __name__ == "__main__":
50
  interface.launch(
51
  server_port=7860,
52
- show_error=True,
53
- enable_queue=True
54
  )
 
3
  import cv2
4
  import time
5
 
6
+ # Load model
7
  model = YOLO('foduucom/plant-leaf-detection-and-classification')
8
 
9
+ # Model configuration
10
  model.overrides.update({
11
  'conf': 0.25,
12
  'iou': 0.45,
13
  'imgsz': 640,
14
+ 'device': '0' if next(model.model.parameters()).is_cuda else 'cpu'
15
  })
16
 
17
  def detect_leaves(image):
 
20
  # Convert image format
21
  img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
22
 
23
+ # Predict
24
+ results = model.predict(img, verbose=False)
 
 
 
 
25
 
26
  # Process results
27
  num_leaves = len(results[0].boxes)
28
  rendered_img = render_result(model=model, image=img, result=results[0])
29
 
30
+ print(f"Processing time: {time.time() - start_time:.2f}s")
31
  return cv2.cvtColor(rendered_img, cv2.COLOR_BGR2RGB), num_leaves
32
 
33
+ # Create interface with queue support
34
  interface = gr.Interface(
35
  fn=detect_leaves,
36
  inputs=gr.Image(label="Plant Image"),
 
39
  gr.Number(label="Leaves Count")
40
  ],
41
  title="πŸƒ Leaf Detection",
42
+ flagging_mode="never" # Updated from allow_flagging
43
  )
44
 
45
  if __name__ == "__main__":
46
  interface.launch(
47
  server_port=7860,
48
+ share=False,
49
+ # Removed enable_queue parameter
50
  )