<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def face_and_energy_detector(image_path, detect_faces=True):
 """ Finds faces and energy in an image """

    source = Image.open(image_path)
    work_width = 800
    if source.mode != 'RGB' or source.bits != 8:
        source24 = source.convert('RGB')
    else:
        source24 = source.copy()

    grayscaleRMY = source24.convert('L', (0.5, 0.419, 0.081, 0))
    w = min(grayscaleRMY.size[0], work_width)
    h = w * grayscaleRMY.size[1] / grayscaleRMY.size[0]
    b = grayscaleRMY.resize((w, h), Image.BICUBIC)
    # b.save('step2.jpg')
    if detect_faces:
        info = do_face_detection(image_path)
        if info:
            return CropInfo(gravity=info)
    b = b.filter(ImageFilter.GaussianBlur(7))
    # b.save('step3.jpg')
    sobelXfilter = ImageFilter.Kernel((3, 3), (1, 0, -1, 2, 0, -2, 1, 0, -1), -.5)
    sobelYfilter = ImageFilter.Kernel((3, 3), (1, 2, 1, 0, 0, 0, -1, -2, -1), -.5)
    b = ImageChops.lighter(b.filter(sobelXfilter), b.filter(sobelYfilter))
    b = b.filter(ImageFilter.FIND_EDGES)
    # b.save('step4.jpg')
    ec = energy_center(b)
    return CropInfo(gravity=ec)