Jarvis-Brain 0.1.11.11__py3-none-any.whl → 0.1.11.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Jarvis_Brain
3
- Version: 0.1.11.11
3
+ Version: 0.1.11.12
4
4
  Summary: Jarvis brain mcp
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: beautifulsoup4
@@ -1,11 +1,11 @@
1
1
  mcp_tools/__init__.py,sha256=_ZzedxbxmVkdRH00ONOjQR31pZW-B8WPn5P2qE6T-Iw,3012
2
- mcp_tools/dp_tools.py,sha256=QK7xcW7s8mieXaNXtCdOALPqSOVYIg72lheneu3xopA,18980
2
+ mcp_tools/dp_tools.py,sha256=hZdIqkuX5cwX05DoRxXBwRfxzqy7wQjMgFgMsv3gOpQ,18959
3
3
  mcp_tools/main.py,sha256=Fgq2PPuc7XCCwXCSVsyoADB0z1vI_gZ07lnLChcrjjg,1167
4
4
  tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  tools/browser_manager.py,sha256=zeYcWuzxoohMdnYUoZbRH7axFC_VtV8MsncfN8y0yw0,2023
6
6
  tools/browser_proxy.py,sha256=VAhuVrBIoXmKyXvCmJh4eRYCWpLIhbTYmFHK8l8eoTA,6590
7
- tools/tools.py,sha256=NPr6ocrqFLW1WVTEhPKF-f0v6JunWtK4ZHKONJTMPn0,12507
8
- jarvis_brain-0.1.11.11.dist-info/METADATA,sha256=EMtP7isXKOp6YS9G4IN6PWmVVJxdZuf3LJ7AcmwnPcQ,265
9
- jarvis_brain-0.1.11.11.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
10
- jarvis_brain-0.1.11.11.dist-info/entry_points.txt,sha256=YFQT4xpkUqt5dM5wlKPQQOqcjMuFrT9iuRAzIpAyH7U,51
11
- jarvis_brain-0.1.11.11.dist-info/RECORD,,
7
+ tools/tools.py,sha256=KvBzefiQbgR-Qa1FsTOGMbVuwTzrK3iXXJgZuFU3UVg,10926
8
+ jarvis_brain-0.1.11.12.dist-info/METADATA,sha256=2FQnuYcTVB9XukYneNY-ejTW7AiDWZZVX6gnJcPdVa8,265
9
+ jarvis_brain-0.1.11.12.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
10
+ jarvis_brain-0.1.11.12.dist-info/entry_points.txt,sha256=YFQT4xpkUqt5dM5wlKPQQOqcjMuFrT9iuRAzIpAyH7U,51
11
+ jarvis_brain-0.1.11.12.dist-info/RECORD,,
mcp_tools/dp_tools.py CHANGED
@@ -325,9 +325,9 @@ def register_get_screenshot(mcp: FastMCP, browser_manager):
325
325
  os.makedirs(html_source_code_local_save_path)
326
326
  timestamp = int(time.time() * 1000)
327
327
  # time.sleep(1)
328
- origin_png = target_tab.get_screenshot(as_bytes="jpg", full_page=True)
329
- compress_png = compress_image_bytes(origin_png, 0.5)
330
- image_path = os.path.join(html_source_code_local_save_path, f"{browser_port}_{tab_id}_{timestamp}.jpg")
328
+ origin_png = target_tab.get_screenshot(as_bytes="png")
329
+ compress_png = compress_image_bytes(origin_png)
330
+ image_path = os.path.join(html_source_code_local_save_path, f"{browser_port}_{tab_id}_{timestamp}.png")
331
331
  with open(image_path, "wb") as f:
332
332
  f.write(compress_png)
333
333
  return dp_mcp_message_pack(
tools/tools.py CHANGED
@@ -212,102 +212,62 @@ def btyes2Base64Img(target_byte):
212
212
  return "data:image/png;base64," + base64.b64encode(target_byte).decode()
213
213
 
214
214
 
215
- # def compress_image_bytes(input_bytes, target_size_mb=1):
216
- # """
217
- # 压缩图片字节数据到目标大小
218
- #
219
- # 参数:
220
- # input_bytes: 输入图片的字节数据
221
- # target_size_mb: 目标大小(MB),默认1MB
222
- #
223
- # 返回:
224
- # 压缩后的图片字节数据
225
- # """
226
- # target_size = target_size_mb * 1024 * 1024 # 转换为字节
227
- #
228
- # # 从字节数据打开图片
229
- # img = Image.open(io.BytesIO(input_bytes))
230
- #
231
- # # 如果是PNG或其他格式,转换为RGB
232
- # if img.mode in ('RGBA', 'LA', 'P'):
233
- # img = img.convert('RGB')
234
- #
235
- # # 初始质量设置
236
- # quality = 95
237
- #
238
- # # 先尝试压缩
239
- # output_buffer = io.BytesIO()
240
- # img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
241
- # output_bytes = output_buffer.getvalue()
242
- #
243
- # # 如果文件仍然太大,逐步降低质量
244
- # while len(output_bytes) > target_size and quality > 10:
245
- # quality -= 5
246
- # output_buffer = io.BytesIO()
247
- # img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
248
- # output_bytes = output_buffer.getvalue()
249
- #
250
- # # 如果降低质量还不够,尝试缩小尺寸
251
- # if len(output_bytes) > target_size:
252
- # width, height = img.size
253
- #
254
- # while len(output_bytes) > target_size and quality > 10:
255
- # # 缩小10%
256
- # width = int(width * 0.9)
257
- # height = int(height * 0.9)
258
- # img_resized = img.resize((width, height), Image.Resampling.LANCZOS)
259
- # output_buffer = io.BytesIO()
260
- # img_resized.save(output_buffer, 'JPEG', quality=quality, optimize=True)
261
- # output_bytes = output_buffer.getvalue()
262
- #
263
- # final_size = len(output_bytes) / (1024 * 1024)
264
- # # print(f"压缩完成!")
265
- # # print(f"原始大小: {len(input_bytes) / (1024 * 1024):.2f}MB")
266
- # # print(f"压缩后大小: {final_size:.2f}MB")
267
- # # print(f"最终质量: {quality}")
268
- #
269
- # return output_bytes
270
- #
271
-
215
+ def compress_image_bytes(input_bytes, target_size_mb=1):
216
+ """
217
+ 压缩图片字节数据到目标大小
272
218
 
219
+ 参数:
220
+ input_bytes: 输入图片的字节数据
221
+ target_size_mb: 目标大小(MB),默认1MB
273
222
 
274
- def compress_image_bytes(input_bytes, target_size_mb=1):
275
- target_size = target_size_mb * 1024 * 1024
223
+ 返回:
224
+ 压缩后的图片字节数据
225
+ """
226
+ target_size = target_size_mb * 1024 * 1024 # 转换为字节
276
227
 
228
+ # 从字节数据打开图片
277
229
  img = Image.open(io.BytesIO(input_bytes))
230
+
231
+ # 如果是PNG或其他格式,转换为RGB
278
232
  if img.mode in ('RGBA', 'LA', 'P'):
279
233
  img = img.convert('RGB')
280
234
 
235
+ # 初始质量设置
281
236
  quality = 95
237
+
238
+ # 先尝试压缩
282
239
  output_buffer = io.BytesIO()
283
240
  img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
284
241
  output_bytes = output_buffer.getvalue()
285
242
 
286
- # 1. 优先降低质量
243
+ # 如果文件仍然太大,逐步降低质量
287
244
  while len(output_bytes) > target_size and quality > 10:
288
245
  quality -= 5
289
246
  output_buffer = io.BytesIO()
290
247
  img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
291
248
  output_bytes = output_buffer.getvalue()
292
249
 
293
- # 2. 如果质量降到底(10)还是太大,开始缩小尺寸
250
+ # 如果降低质量还不够,尝试缩小尺寸
294
251
  if len(output_bytes) > target_size:
295
252
  width, height = img.size
296
253
 
297
- # 修改点:这里去掉了 'and quality > 10',改为防止图片缩得太小 (width > 100)
298
- while len(output_bytes) > target_size and width > 100:
254
+ while len(output_bytes) > target_size and quality > 10:
255
+ # 缩小10%
299
256
  width = int(width * 0.9)
300
257
  height = int(height * 0.9)
301
-
302
- # 重新调整尺寸
303
258
  img_resized = img.resize((width, height), Image.Resampling.LANCZOS)
304
-
305
259
  output_buffer = io.BytesIO()
306
- # 注意:这里继续使用当前的最低质量(10)进行保存,或者你可以适当回调一点质量
307
260
  img_resized.save(output_buffer, 'JPEG', quality=quality, optimize=True)
308
261
  output_bytes = output_buffer.getvalue()
309
262
 
263
+ final_size = len(output_bytes) / (1024 * 1024)
264
+ # print(f"压缩完成!")
265
+ # print(f"原始大小: {len(input_bytes) / (1024 * 1024):.2f}MB")
266
+ # print(f"压缩后大小: {final_size:.2f}MB")
267
+ # print(f"最终质量: {quality}")
268
+
310
269
  return output_bytes
270
+
311
271
  # todo: 大致盘一下各种判定的逻辑【以下的所有压缩比之间的差距均取“绝对值”】
312
272
  # 1. 如果requests、无头、有头获取到的压缩比之间从差距都在15%以内,则认定该页面是静态页面,此时优先使用requests请求
313
273
  # 2. 如果requests的status_code为特定的412,或者521,则判定是瑞数和jsl。[此时还有一个特点:requests的压缩比会与其他两种方式获取到的压缩比差距非常大(一两千的那种)]