Spaces:
Sleeping
Sleeping
Update main.py
Browse files133 unmodified lines134135136137138139140141142143144145146147148149150151152153154155156157133 unmodified lines_GLOBAL_ENGINE = Noneif not os.path.exists(ENGINE_PATH):raise HTTPException(status_code=500, detail=f"Engine NOT FOUND at {ENGINE_PATH}")try:transport, engine = await chess.engine.popen_uci(ENGINE_PATH)# Configure onceawait engine.configure({"Hash": 256, "Threads": 1}) # More conservative for singletonif os.path.exists(NNUE_PATH):try:await engine.configure({"EvalFile": NNUE_PATH})except Exception:pass_GLOBAL_ENGINE = enginereturn engineexcept Exception as e:raise HTTPException(status_code=500, detail=f"Failed to start engine: {str(e)}")def get_normalized_score(info) -> tuple[float, Optional[int]]:"""Returns the score from White's perspective in centipawns."""133 unmodified lines134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171133 unmodified lines_GLOBAL_ENGINE = Noneif not os.path.exists(ENGINE_PATH):raise HTTPException(status_code=500, detail=f"Engine binary NOT FOUND at {ENGINE_PATH}")print(f"[DEBUG] Attempting to start engine at {ENGINE_PATH}")try:transport, engine = await chess.engine.popen_uci(ENGINE_PATH)print(f"[DEBUG] Engine process started. ID: {transport.get_pid()}")# Configure onceawait engine.configure({"Hash": 128, "Threads": 1})if os.path.exists(NNUE_PATH):print(f"[DEBUG] Found NNUE at {NNUE_PATH}. Attempting to load...")try:await engine.configure({"EvalFile": NNUE_PATH})print("[DEBUG] NNUE loaded successfully.")except Exception as ne:print(f"[ERROR] NNUE load failed: {str(ne)}")else:print(f"[WARNING] NNUE NOT FOUND at {NNUE_PATH}")_GLOBAL_ENGINE = enginereturn engineexcept Exception as e:print(f"[CRITICAL] Engine failed to start: {str(e)}")# Try to gather more info by running the binary directly brieflyimport subprocesstry:diag = subprocess.run([ENGINE_PATH, "uci"], capture_output=True, text=True, timeout=2)print(f"[DIAG] Engine output: {diag.stdout} | Error: {diag.stderr}")except Exception as de:print(f"[DIAG] Could not run diagnosis: {str(de)}")raise HTTPException(status_code=500, detail=f"Engine Crash: {str(e)}")def get_normalized_score(info) -> tuple[float, Optional[int]]:"""Returns the score from White's perspective in centipawns."""
main.py+19-5