kfahn commited on
Commit
a3e866a
·
verified ·
1 Parent(s): b34fb7f

Update app.py

Browse files

revert to previous version

Files changed (1) hide show
  1. app.py +27 -26
app.py CHANGED
@@ -83,33 +83,33 @@ async def capture_screenshot(image_type: str):
83
  await browser.close()
84
  print("Screenshot saved!")
85
 
86
- def crop_based_on_bg(image_path: str, bg_color=(59, 59, 59), tolerance=10):
87
- img = Image.open(image_path).convert("RGB")
88
- img_array = np.array(img)
89
 
90
- # Define fixed crop for top header
91
- top_crop = 50
92
- #width, height = img.size
93
 
94
- # Get height & width
95
- height, width, _ = img_array.shape
96
 
97
- # Extract the portion of the image below the fixed header
98
- img_no_header = img_array[top_crop:, :, :]
99
 
100
- # Compute a mask for pixels that are NOT within the background tolerance
101
- lower_bound = np.array(bg_color) - tolerance
102
- upper_bound = np.array(bg_color) + tolerance
103
- mask = np.any((img_no_header < lower_bound) | (img_no_header > upper_bound), axis=2)
104
 
105
- # Find leftmost and rightmost non-background pixels
106
- col_sums = mask.sum(axis=0)
107
- left_crop = np.argmax(col_sums > 0) # First column with content
108
- right_crop = width - np.argmax(col_sums[::-1] > 0) # Last column with content
109
 
110
- # Crop and save
111
- cropped_img = img.crop((left_crop, top_crop, right_crop, height))
112
- return cropped_img
113
 
114
  @tool
115
  def grab_image(image_type: str) -> Image:
@@ -131,12 +131,13 @@ def grab_image(image_type: str) -> Image:
131
 
132
  print("Loading image for Gradio...")
133
 
134
- cropped_img = crop_based_on_bg("img.png", (59, 59, 59), 10)
135
- #img = Image.open("img.png")
136
- #header_height = 50
 
 
137
 
138
- #cropped_img = img.crop((left_crop, header_height, right_crop, img.height))
139
- #cropped_img = crop_based_on_bg(img, left_crop, header_height, right_crop, img.height)
140
  return cropped_img
141
 
142
  @tool
 
83
  await browser.close()
84
  print("Screenshot saved!")
85
 
86
+ # def crop_based_on_bg(image_path: str, bg_color=(59, 59, 59), tolerance=10):
87
+ # img = Image.open(image_path).convert("RGB")
88
+ # img_array = np.array(img)
89
 
90
+ # # Define fixed crop for top header
91
+ # top_crop = 50
92
+ # #width, height = img.size
93
 
94
+ # # Get height & width
95
+ # height, width, _ = img_array.shape
96
 
97
+ # # Extract the portion of the image below the fixed header
98
+ # img_no_header = img_array[top_crop:, :, :]
99
 
100
+ # # Compute a mask for pixels that are NOT within the background tolerance
101
+ # lower_bound = np.array(bg_color) - tolerance
102
+ # upper_bound = np.array(bg_color) + tolerance
103
+ # mask = np.any((img_no_header < lower_bound) | (img_no_header > upper_bound), axis=2)
104
 
105
+ # # Find leftmost and rightmost non-background pixels
106
+ # col_sums = mask.sum(axis=0)
107
+ # left_crop = np.argmax(col_sums > 0) # First column with content
108
+ # right_crop = width - np.argmax(col_sums[::-1] > 0) # Last column with content
109
 
110
+ # # Crop and save
111
+ # cropped_img = img.crop((left_crop, top_crop, right_crop, height))
112
+ # return cropped_img
113
 
114
  @tool
115
  def grab_image(image_type: str) -> Image:
 
131
 
132
  print("Loading image for Gradio...")
133
 
134
+ #cropped_img = crop_based_on_bg("img.png", (59, 59, 59), 10)
135
+ img = Image.open("img.png")
136
+ header_height = 50
137
+ left_crop = 0
138
+ right_crop = 0
139
 
140
+ cropped_img = img.crop((left_crop, header_height, right_crop, img.height))
 
141
  return cropped_img
142
 
143
  @tool