Sanshruth commited on
Commit
d1304e5
·
verified ·
1 Parent(s): a1c69a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -26,9 +26,9 @@ logger.info(f"OpenCV using {cv2.getNumThreads()} threads out of {cpu_cores} avai
26
 
27
  def extract_first_frame(stream_url):
28
  """
29
- Extracts the first available frame from the IP camera stream and returns it as a PIL image.
30
  """
31
- logger.info("Attempting to extract the first frame from the stream...")
32
  cap = cv2.VideoCapture(stream_url)
33
  if not cap.isOpened():
34
  logger.error("Error: Could not open stream.")
@@ -38,15 +38,15 @@ def extract_first_frame(stream_url):
38
  cap.release()
39
 
40
  if not ret:
41
- logger.error("Error: Could not read the first frame.")
42
- return None, "Error: Could not read the first frame."
43
 
44
  # Convert the frame to a PIL image
45
  frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
46
  pil_image = Image.fromarray(frame_rgb)
47
 
48
- logger.info("First frame extracted successfully.")
49
- return pil_image, "First frame extracted successfully."
50
 
51
  def update_line(image, evt: gr.SelectData):
52
  """
@@ -296,7 +296,7 @@ with gr.Blocks() as demo:
296
 
297
  # Step 2: Select classes to detect
298
  gr.Markdown("### Step 2: Select Classes to Detect")
299
- model = YOLO(model="yolov8n.pt") # Load the model to get class names
300
  class_names = list(model.names.values()) # Get class names
301
  selected_classes = gr.CheckboxGroup(choices=class_names, label="Select Classes to Detect")
302
 
 
26
 
27
  def extract_first_frame(stream_url):
28
  """
29
+ Extracts the current frame from the IP camera stream and returns it as a PIL image.
30
  """
31
+ logger.info("Attempting to extract the current frame from the stream...")
32
  cap = cv2.VideoCapture(stream_url)
33
  if not cap.isOpened():
34
  logger.error("Error: Could not open stream.")
 
38
  cap.release()
39
 
40
  if not ret:
41
+ logger.error("Error: Could not read the current frame.")
42
+ return None, "Error: Could not read the current frame."
43
 
44
  # Convert the frame to a PIL image
45
  frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
46
  pil_image = Image.fromarray(frame_rgb)
47
 
48
+ logger.info("Current frame extracted successfully.")
49
+ return pil_image, "Current frame extracted successfully."
50
 
51
  def update_line(image, evt: gr.SelectData):
52
  """
 
296
 
297
  # Step 2: Select classes to detect
298
  gr.Markdown("### Step 2: Select Classes to Detect")
299
+ model = YOLO(model="yolo12n.pt") # Load the model to get class names
300
  class_names = list(model.names.values()) # Get class names
301
  selected_classes = gr.CheckboxGroup(choices=class_names, label="Select Classes to Detect")
302