import gradio as gr import cv2 import numpy as np # Function to compare two images and highlight differences def compare_images(mockup, ui_screenshot, check_text, check_color, check_spacing): # Convert images to numpy arrays mockup_array = np.array(mockup) ui_screenshot_array = np.array(ui_screenshot) # Resize images to the same dimensions if mockup_array.shape != ui_screenshot_array.shape: height, width = max(mockup_array.shape[0], ui_screenshot_array.shape[0]), max(mockup_array.shape[1], ui_screenshot_array.shape[1]) mockup_array = cv2.resize(mockup_array, (width, height)) ui_screenshot_array = cv2.resize(ui_screenshot_array, (width, height)) # Convert images to RGB mockup_rgb = cv2.cvtColor(mockup_array, cv2.COLOR_RGB2BGR) ui_screenshot_rgb = cv2.cvtColor(ui_screenshot_array, cv2.COLOR_RGB2BGR) # Compute the absolute difference between the two images difference = cv2.absdiff(mockup_rgb, ui_screenshot_rgb) # Threshold the difference image to get a binary image _, thresh = cv2.threshold(cv2.cvtColor(difference, cv2.COLOR_BGR2GRAY), 30, 255, cv2.THRESH_BINARY) # Find contours of the differences contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # Create a copy of the original image to draw the differences highlighted_image = mockup_array.copy() # Define colors for different checks colors = { "text": (255, 0, 0), # Blue for text "color": (0, 255, 0), # Green for color "spacing": (0, 0, 255) # Red for spacing } # Draw contours on the highlighted image with different colors based on the checks for contour in contours: if check_text: cv2.drawContours(highlighted_image, [contour], -1, colors["text"], 2) if check_color: cv2.drawContours(highlighted_image, [contour], -1, colors["color"], 2) if check_spacing: cv2.drawContours(highlighted_image, [contour], -1, colors["spacing"], 2) return highlighted_image # Create Gradio interface with gr.Blocks() as demo: # Load Google Fonts for Roboto and Press Start 2P gr.Markdown(""" """) # Display logo and title side by side gr.Markdown("""