jithenderchoudary commited on
Commit
aac3d7b
·
verified ·
1 Parent(s): 730915d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -13
app.py CHANGED
@@ -1,19 +1,16 @@
1
  import cv2
2
  import numpy as np
3
- from matplotlib import pyplot as plt
4
 
5
- # Load the two images provided by the user
6
- original_image_path = "/mnt/data/artwork done by us_page-0001.jpg"
7
- adjusted_image_path = "/mnt/data/drawing sent by party (1)_page-0001.jpg"
 
8
 
9
- # Read images using OpenCV
10
- original_image = cv2.imread(original_image_path)
11
- adjusted_image = cv2.imread(adjusted_image_path)
12
 
13
- # Check if images loaded correctly
14
- if original_image is None or adjusted_image is None:
15
- comparison_result = "Error: One or both images could not be loaded."
16
- else:
17
  # Resize the adjusted image to match the dimensions of the original for accurate comparison
18
  original_image_resized = cv2.resize(original_image, (adjusted_image.shape[1], adjusted_image.shape[0]))
19
 
@@ -39,7 +36,7 @@ else:
39
  _, threshold_diff = cv2.threshold(difference, 30, 255, cv2.THRESH_BINARY)
40
 
41
  # Save the difference image
42
- difference_image_path = "/mnt/data/difference_image.jpg"
43
  cv2.imwrite(difference_image_path, threshold_diff)
44
 
45
  # Prepare results summary
@@ -54,4 +51,37 @@ else:
54
  "Difference Image": difference_image_path
55
  }
56
 
57
- comparison_result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import cv2
2
  import numpy as np
3
+ import gradio as gr
4
 
5
+ def compare_images(original_image_path, adjusted_image_path):
6
+ # Read images using OpenCV
7
+ original_image = cv2.imread(original_image_path)
8
+ adjusted_image = cv2.imread(adjusted_image_path)
9
 
10
+ # Check if images loaded correctly
11
+ if original_image is None or adjusted_image is None:
12
+ return "Error: One or both images could not be loaded."
13
 
 
 
 
 
14
  # Resize the adjusted image to match the dimensions of the original for accurate comparison
15
  original_image_resized = cv2.resize(original_image, (adjusted_image.shape[1], adjusted_image.shape[0]))
16
 
 
36
  _, threshold_diff = cv2.threshold(difference, 30, 255, cv2.THRESH_BINARY)
37
 
38
  # Save the difference image
39
+ difference_image_path = "difference_image.jpg"
40
  cv2.imwrite(difference_image_path, threshold_diff)
41
 
42
  # Prepare results summary
 
51
  "Difference Image": difference_image_path
52
  }
53
 
54
+ return comparison_result, threshold_diff
55
+
56
+ # Gradio interface
57
+ def gradio_compare_images(original_image, adjusted_image):
58
+ # Save images temporarily
59
+ original_image_path = "original_image.jpg"
60
+ adjusted_image_path = "adjusted_image.jpg"
61
+
62
+ cv2.imwrite(original_image_path, original_image)
63
+ cv2.imwrite(adjusted_image_path, adjusted_image)
64
+
65
+ # Compare images
66
+ result, diff_image = compare_images(original_image_path, adjusted_image_path)
67
+
68
+ return result, diff_image
69
+
70
+ # Create Gradio interface
71
+ iface = gr.Interface(
72
+ fn=gradio_compare_images,
73
+ inputs=[
74
+ gr.inputs.Image(type="numpy", label="Original Image"),
75
+ gr.inputs.Image(type="numpy", label="Adjusted Image")
76
+ ],
77
+ outputs=[
78
+ gr.outputs.JSON(label="Comparison Result"),
79
+ gr.outputs.Image(type="numpy", label="Difference Image")
80
+ ],
81
+ title="Image Comparison Tool",
82
+ description="Upload two images to compare dimensions, brightness, and highlight differences."
83
+ )
84
+
85
+ # Launch the Gradio app
86
+ iface.launch()
87
+