Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -134,24 +134,38 @@ async def get_engine():
|
|
| 134 |
_GLOBAL_ENGINE = None
|
| 135 |
|
| 136 |
if not os.path.exists(ENGINE_PATH):
|
| 137 |
-
raise HTTPException(status_code=500, detail=f"Engine NOT FOUND at {ENGINE_PATH}")
|
| 138 |
|
|
|
|
| 139 |
try:
|
| 140 |
transport, engine = await chess.engine.popen_uci(ENGINE_PATH)
|
|
|
|
| 141 |
|
| 142 |
# Configure once
|
| 143 |
-
await engine.configure({"Hash":
|
| 144 |
|
| 145 |
if os.path.exists(NNUE_PATH):
|
|
|
|
| 146 |
try:
|
| 147 |
await engine.configure({"EvalFile": NNUE_PATH})
|
| 148 |
-
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
_GLOBAL_ENGINE = engine
|
| 152 |
return engine
|
| 153 |
except Exception as e:
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
def get_normalized_score(info) -> tuple[float, Optional[int]]:
|
| 157 |
"""Returns the score from White's perspective in centipawns."""
|
|
|
|
| 134 |
_GLOBAL_ENGINE = None
|
| 135 |
|
| 136 |
if not os.path.exists(ENGINE_PATH):
|
| 137 |
+
raise HTTPException(status_code=500, detail=f"Engine binary NOT FOUND at {ENGINE_PATH}")
|
| 138 |
|
| 139 |
+
print(f"[DEBUG] Attempting to start engine at {ENGINE_PATH}")
|
| 140 |
try:
|
| 141 |
transport, engine = await chess.engine.popen_uci(ENGINE_PATH)
|
| 142 |
+
print(f"[DEBUG] Engine process started. ID: {transport.get_pid()}")
|
| 143 |
|
| 144 |
# Configure once
|
| 145 |
+
await engine.configure({"Hash": 128, "Threads": 1})
|
| 146 |
|
| 147 |
if os.path.exists(NNUE_PATH):
|
| 148 |
+
print(f"[DEBUG] Found NNUE at {NNUE_PATH}. Attempting to load...")
|
| 149 |
try:
|
| 150 |
await engine.configure({"EvalFile": NNUE_PATH})
|
| 151 |
+
print("[DEBUG] NNUE loaded successfully.")
|
| 152 |
+
except Exception as ne:
|
| 153 |
+
print(f"[ERROR] NNUE load failed: {str(ne)}")
|
| 154 |
+
else:
|
| 155 |
+
print(f"[WARNING] NNUE NOT FOUND at {NNUE_PATH}")
|
| 156 |
|
| 157 |
_GLOBAL_ENGINE = engine
|
| 158 |
return engine
|
| 159 |
except Exception as e:
|
| 160 |
+
print(f"[CRITICAL] Engine failed to start: {str(e)}")
|
| 161 |
+
# Try to gather more info by running the binary directly briefly
|
| 162 |
+
import subprocess
|
| 163 |
+
try:
|
| 164 |
+
diag = subprocess.run([ENGINE_PATH, "uci"], capture_output=True, text=True, timeout=2)
|
| 165 |
+
print(f"[DIAG] Engine output: {diag.stdout} | Error: {diag.stderr}")
|
| 166 |
+
except Exception as de:
|
| 167 |
+
print(f"[DIAG] Could not run diagnosis: {str(de)}")
|
| 168 |
+
raise HTTPException(status_code=500, detail=f"Engine Crash: {str(e)}")
|
| 169 |
|
| 170 |
def get_normalized_score(info) -> tuple[float, Optional[int]]:
|
| 171 |
"""Returns the score from White's perspective in centipawns."""
|