Spaces:
Running
Running
Update agent.py
Browse files
agent.py
CHANGED
@@ -247,7 +247,7 @@ class ExcelReaderTool(Tool):
|
|
247 |
|
248 |
|
249 |
|
250 |
-
|
251 |
|
252 |
@tool
|
253 |
def PNG2FENTool(png_file: str) -> str:
|
@@ -265,22 +265,37 @@ 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 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
except FileNotFoundError:
|
280 |
raise FileNotFoundError("PNG file not found.")
|
281 |
-
|
282 |
-
except Exception as e:
|
283 |
-
raise ValueError("Error processing PNG file: " + str(e))
|
284 |
|
285 |
def process_text_to_fen(text):
|
286 |
"""
|
|
|
247 |
|
248 |
|
249 |
|
250 |
+
|
251 |
|
252 |
@tool
|
253 |
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)
|
271 |
+
fen_candidates = [text for text in result if validate_fen_format(text)]
|
272 |
+
|
273 |
+
if not fen_candidates:
|
274 |
+
raise ValueError("No valid FEN found in image")
|
275 |
+
|
276 |
+
return fen_candidates[0]
|
277 |
+
|
278 |
+
except Exception as e:
|
279 |
+
raise ValueError(f"OCR processing failed: {str(e)}")
|
280 |
+
|
281 |
+
|
282 |
+
# try:
|
283 |
+
# # Open the PNG file using PIL
|
284 |
+
# image = Image.open(png_file)
|
285 |
+
#
|
286 |
+
# # Use pytesseract to extract text from the image
|
287 |
+
# text = pytesseract.image_to_string(image)
|
288 |
+
#
|
289 |
+
# # Process the extracted text to get the FEN position string
|
290 |
+
# fen_position = process_text_to_fen(text)
|
291 |
+
#
|
292 |
+
# return fen_position
|
293 |
+
#
|
294 |
except FileNotFoundError:
|
295 |
raise FileNotFoundError("PNG file not found.")
|
296 |
+
#
|
297 |
+
# except Exception as e:
|
298 |
+
# raise ValueError("Error processing PNG file: " + str(e))
|
299 |
|
300 |
def process_text_to_fen(text):
|
301 |
"""
|