No problem, here you go.

    import cv2
    import numpy as np

    # Load input image
    img = cv2.imread('input_photo.jpg')

    # Convert image to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # Detect edges in the image
    edges = cv2.Canny(gray, 50, 150, apertureSize=3)

    # Detect lines in the image using Hough transform
    lines = cv2.HoughLines(edges, 1, np.pi / 180, 200)

    # Compute the average angle of the detected lines
    angles = []
    for line in lines:
        for rho, theta in line:
            a = np.cos(theta)
            b = np.sin(theta)
            x0 = a * rho
            y0 = b * rho
            x1 = int(x0 + 1000 * (-b))
            y1 = int(y0 + 1000 * (a))
            x2 = int(x0 - 1000 * (-b))
            y2 = int(y0 - 1000 * (a))
            angle = np.arctan2(y2 - y1, x2 - x1) * 180 / np.pi
            angles.append(angle)

    # Rotate the image by the average angle
    avg_angle = np.mean(angles)
    rows, cols, _ = img.shape
    M = cv2.getRotationMatrix2D((cols / 2, rows / 2), avg_angle, 1)
    rotated = cv2.warpAffine(img, M, (cols, rows))

    # Save the rotated image
    cv2.imwrite('output_photo.png', rotated)
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence