Spaces:
Sleeping
Sleeping
Commit
·
2e66235
verified
·
0
Parent(s):
initial commit
Browse files- .gitattributes +35 -0
- README.md +12 -0
- app.py +83 -0
- requirements.txt +2 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: SpotTheDifferenceGame
|
| 3 |
+
emoji: 🦀
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.6.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Function to compare two images and highlight differences
|
| 6 |
+
def compare_images(mockup, ui_screenshot, check_text, check_color, check_spacing):
|
| 7 |
+
# Convert images to numpy arrays
|
| 8 |
+
mockup_array = np.array(mockup)
|
| 9 |
+
ui_screenshot_array = np.array(ui_screenshot)
|
| 10 |
+
|
| 11 |
+
# Resize images to the same dimensions
|
| 12 |
+
if mockup_array.shape != ui_screenshot_array.shape:
|
| 13 |
+
height, width = max(mockup_array.shape[0], ui_screenshot_array.shape[0]), max(mockup_array.shape[1], ui_screenshot_array.shape[1])
|
| 14 |
+
mockup_array = cv2.resize(mockup_array, (width, height))
|
| 15 |
+
ui_screenshot_array = cv2.resize(ui_screenshot_array, (width, height))
|
| 16 |
+
|
| 17 |
+
# Convert images to RGB
|
| 18 |
+
mockup_rgb = cv2.cvtColor(mockup_array, cv2.COLOR_RGB2BGR)
|
| 19 |
+
ui_screenshot_rgb = cv2.cvtColor(ui_screenshot_array, cv2.COLOR_RGB2BGR)
|
| 20 |
+
|
| 21 |
+
# Compute the absolute difference between the two images
|
| 22 |
+
difference = cv2.absdiff(mockup_rgb, ui_screenshot_rgb)
|
| 23 |
+
|
| 24 |
+
# Threshold the difference image to get a binary image
|
| 25 |
+
_, thresh = cv2.threshold(cv2.cvtColor(difference, cv2.COLOR_BGR2GRAY), 30, 255, cv2.THRESH_BINARY)
|
| 26 |
+
|
| 27 |
+
# Find contours of the differences
|
| 28 |
+
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
| 29 |
+
|
| 30 |
+
# Create a copy of the original image to draw the differences
|
| 31 |
+
highlighted_image = mockup_array.copy()
|
| 32 |
+
|
| 33 |
+
# Define colors for different checks
|
| 34 |
+
colors = {
|
| 35 |
+
"text": (255, 0, 0), # Blue for text
|
| 36 |
+
"color": (0, 255, 0), # Green for color
|
| 37 |
+
"spacing": (0, 0, 255) # Red for spacing
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# Draw contours on the highlighted image with different colors based on the checks
|
| 41 |
+
for contour in contours:
|
| 42 |
+
if check_text:
|
| 43 |
+
cv2.drawContours(highlighted_image, [contour], -1, colors["text"], 2)
|
| 44 |
+
if check_color:
|
| 45 |
+
cv2.drawContours(highlighted_image, [contour], -1, colors["color"], 2)
|
| 46 |
+
if check_spacing:
|
| 47 |
+
cv2.drawContours(highlighted_image, [contour], -1, colors["spacing"], 2)
|
| 48 |
+
|
| 49 |
+
return highlighted_image
|
| 50 |
+
|
| 51 |
+
# Create Gradio interface
|
| 52 |
+
with gr.Blocks() as demo:
|
| 53 |
+
# Load Google Fonts for Roboto and Press Start 2P
|
| 54 |
+
gr.Markdown("""
|
| 55 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 56 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 57 |
+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Press+Start+2P&display=swap" rel="stylesheet">
|
| 58 |
+
""")
|
| 59 |
+
|
| 60 |
+
# Display logo and title side by side
|
| 61 |
+
gr.Markdown("""
|
| 62 |
+
<div style='display: flex; align-items: center; justify-content: center;'>
|
| 63 |
+
<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/CeX_Logo.webp/320px-CeX_Logo.webp.png' width='100' style='margin-right: 10px;'/>
|
| 64 |
+
<h1 style='font-family: "Press Start 2P", cursive; margin: 0;'>Spot The Difference Game</h1>
|
| 65 |
+
</div>
|
| 66 |
+
""")
|
| 67 |
+
|
| 68 |
+
with gr.Row():
|
| 69 |
+
mockup_input = gr.Image(label="Mockup Image")
|
| 70 |
+
ui_screenshot_input = gr.Image(label="UI Screenshot")
|
| 71 |
+
with gr.Row():
|
| 72 |
+
check_text = gr.Checkbox(label="Check Text")
|
| 73 |
+
check_color = gr.Checkbox(label="Check Color", value=True) # Default to True to spot minor color variations
|
| 74 |
+
check_spacing = gr.Checkbox(label="Check Spacing")
|
| 75 |
+
with gr.Row():
|
| 76 |
+
compare_button = gr.Button("Compare Images")
|
| 77 |
+
output_image = gr.Image(label="Highlighted Differences")
|
| 78 |
+
|
| 79 |
+
# Set up the button click event
|
| 80 |
+
compare_button.click(compare_images, inputs=[mockup_input, ui_screenshot_input, check_text, check_color, check_spacing], outputs=output_image)
|
| 81 |
+
|
| 82 |
+
# Launch the Gradio app
|
| 83 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
opencv-python
|
| 2 |
+
numpy
|