SergeyO7 commited on
Commit
ff92442
·
verified ·
1 Parent(s): b9fde43

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +16 -1
agent.py CHANGED
@@ -6,7 +6,7 @@ import pandas as pd
6
  from typing import Optional
7
  from token_bucket import Limiter, MemoryStorage
8
  import yaml
9
- from PIL import Image
10
  import requests
11
  from io import BytesIO
12
  from markdownify import markdownify
@@ -265,6 +265,21 @@ def PNG2FENTool(png_file: str) -> str:
265
  # If the PNG file cannot be processed or does not contain a valid chess board.
266
 
267
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  import easyocr
269
  reader = easyocr.Reader(['en'])
270
  result = reader.readtext(png_file, detail=0)
 
6
  from typing import Optional
7
  from token_bucket import Limiter, MemoryStorage
8
  import yaml
9
+ from PIL import Image, ImageOps
10
  import requests
11
  from io import BytesIO
12
  from markdownify import markdownify
 
265
  # If the PNG file cannot be processed or does not contain a valid chess board.
266
 
267
  try:
268
+ # Open and preprocess image
269
+ img = Image.open(png_file)
270
+ img = ImageOps.exif_transpose(img) # Fix orientation
271
+ img = img.convert("L") # Grayscale
272
+
273
+ # Resize using LANCZOS instead of ANTIALIAS
274
+ width, height = img.size
275
+ new_size = (width*2, height*2)
276
+ img = img.resize(new_size, Image.LANCZOS) # Updated here
277
+
278
+ # Save temp file for OCR
279
+ temp_path = "chess_temp.png"
280
+ img.save(temp_path)
281
+
282
+ # Perform OCR
283
  import easyocr
284
  reader = easyocr.Reader(['en'])
285
  result = reader.readtext(png_file, detail=0)