Spaces:
Sleeping
Sleeping
import cv2 | |
import numpy as np | |
import constants | |
from langchain_core.prompts import ChatPromptTemplate | |
from langchain_google_genai import ChatGoogleGenerativeAI | |
from langgraph.graph import StateGraph, END | |
from typing import TypedDict, List, Dict | |
import google.generativeai as genai | |
def image_to_fen(image_bytes): | |
genai.configure(api_key=constants.API_KEY) | |
model = genai.GenerativeModel(constants.MODEL) | |
response = model.generate_content([ | |
{"mime_type": "image/jpeg", "data": image_bytes}, | |
"Describe the chessboard in this image and provide the FEN notation." | |
]) | |
print(response.text) | |
return '' | |
if __name__ == '__main__': | |
# Example usage: | |
# 1. Load an image from a file (replace with your image path) | |
image_path = r"C:\Users\agazo\Downloads\cca530fc-4052-43b2-b130-b30968d8aa44_file.png" # Replace with a valid image path | |
try: | |
with open(image_path, "rb") as image_file: | |
image_bytes = image_file.read() | |
except FileNotFoundError: | |
print(f"Error: File not found at {image_path}. Please make sure the path is correct and the file exists.") | |
exit() | |
# 2. Call the function | |
fen = image_to_fen(image_bytes) | |
print(f"FEN: {fen}") | |
#resultado esperado do FEN; 1K6/1PP5/P2RBBqP/4n3/Q7/p2b4/1pp3pp/1k2r3 w - - 0 1 |