File size: 1,899 Bytes
8ff7d8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import sys
import json
from pathlib import Path

# Add the src directory to the path so we can import the modules
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))

# Import the module directly from the path
src_dir = str(Path(__file__).parent.parent / "src")
sys.path.insert(0, src_dir)

def main():
    print("Testing chess image analysis")
    
    # Path to the test chess image
    test_image = str(Path(__file__).parent.parent / "data/downloaded_files" / "cca530fc-4052-43b2-b130-b30968d8aa44.png")
    
    if not os.path.exists(test_image):
        print(f"Error: Test image not found at {test_image}")
        return
    
    print(f"Processing chess image: {test_image}")
    
    # Import here to avoid dependency issues
    from file_processing_tool import process_image_file
    
    # Process the image using our file processing tool
    result = process_image_file(test_image)
    
    # Display the result
    chess_analysis = result.get("chess_analysis", None)
    
    if chess_analysis and isinstance(chess_analysis, dict) and "recommended_move" in chess_analysis:
        print("\nChess Position Analysis:")
        print(f"Recommended move: {chess_analysis['recommended_move']}")
        print(f"Explanation: {chess_analysis.get('explanation', 'No explanation provided')}")
        
        # Demonstrate how this can be used to answer the question
        question = "Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation."
        print(f"\nQuestion: {question}")
        print(f"Answer: {chess_analysis['recommended_move']}")
    else:
        print("\nCould not determine the answer from the analysis.")
        if result.get("error"):
            print(f"Error: {result['error']}")

if __name__ == "__main__":
    main()