WebRTC video_frame_callback + CustomDetectionModel ImageAI: bug

Hi! I am trying to detect some objects in realtime using Streamlit WebRTC.

But if we run the code below, def callback() will be called only once! (Should - each frame.)

def callback(frame):
    imga = frame.to_ndarray(format="bgr24")
    imgb = Image.fromarray(imga.astype('uint8'))

    imgb.save('pages/filename.png')
    detections, detected_image = detector.detectObjectsFromImage(input_image="pages/filename.png", output_type="array")
    # detector.detectObjectsFromImage(input_image="pages/filename.png", output_image_path="pages/ender.png")

    print("Обновлено")

    # image = Image.open('pages/ender.png')
    # image_array = np.array(image)
    # framer = av.VideoFrame.from_ndarray(image_array, format='rgb24')

    for eachObject in detections:
        print(eachObject["name"], " : ", eachObject["percentage_probability"], " : ", eachObject["box_points"])
        cv2.rectangle(detected_image, (eachObject["box_points"][0], eachObject["box_points"][1]),
                      (eachObject["box_points"][2], eachObject["box_points"][3]), (0, 255, 0), 2)
        cv2.putText(detected_image, eachObject["name"],
                    (eachObject["box_points"][0], eachObject["box_points"][1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                    (0, 255, 0), 2)

    return av.VideoFrame.from_ndarray(detected_image, format="bgr24")


webrtc_streamer(key="example", video_frame_callback=callback)

I also tried to run this code without using imageAI model, and it worked. So, probably, problem is in “return” data format, or in detector.detectObjectsFromImage


Can you please help me find a bug in the callback method? I will be very grateful!