Spaces:
Sleeping
Sleeping
Merge pull request #3 from Narendra523116/getFen
Browse files
__pycache__/main.cpython-311.pyc
CHANGED
Binary files a/__pycache__/main.cpython-311.pyc and b/__pycache__/main.cpython-311.pyc differ
|
|
main.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import io
|
2 |
-
from fastapi import FastAPI, File, UploadFile
|
3 |
from fastapi.responses import JSONResponse, StreamingResponse
|
4 |
from PIL import Image, UnidentifiedImageError
|
5 |
from routes.segmentation import segment_chess_board
|
@@ -88,15 +88,15 @@ async def get_coords(file: UploadFile = File(...)):
|
|
88 |
|
89 |
|
90 |
@app.post("/getFen")
|
91 |
-
async def get_fen(file : UploadFile = File(), perspective : str = "w", next_to_move : str = "w"):
|
92 |
|
93 |
if perspective not in ["w" , "b"]:
|
94 |
return JSONResponse(content={"error" : "Perspective should be w (white) or b (black)"}, status_code=500)
|
95 |
|
96 |
-
if
|
97 |
-
return JSONResponse(content={"error" : "
|
98 |
-
|
99 |
|
|
|
100 |
try:
|
101 |
image_content = await file.read()
|
102 |
if not image_content:
|
@@ -117,7 +117,7 @@ async def get_fen(file : UploadFile = File(), perspective : str = "w", next_to_m
|
|
117 |
if "error" in detection_results:
|
118 |
return JSONResponse(content=detection_results, status_code=400)
|
119 |
|
120 |
-
fen = gen_fen(detection_results, perspective)
|
121 |
if not fen:
|
122 |
return JSONResponse(content={"error": "FEN generation failed", "details": "Invalid input data"}, status_code=500)
|
123 |
|
|
|
1 |
import io
|
2 |
+
from fastapi import FastAPI, File, UploadFile, Form
|
3 |
from fastapi.responses import JSONResponse, StreamingResponse
|
4 |
from PIL import Image, UnidentifiedImageError
|
5 |
from routes.segmentation import segment_chess_board
|
|
|
88 |
|
89 |
|
90 |
@app.post("/getFen")
|
91 |
+
async def get_fen(file : UploadFile = File(), perspective : str = Form("w"), next_to_move : str = Form("w")):
|
92 |
|
93 |
if perspective not in ["w" , "b"]:
|
94 |
return JSONResponse(content={"error" : "Perspective should be w (white) or b (black)"}, status_code=500)
|
95 |
|
96 |
+
if next_to_move not in ["w" , "b"]:
|
97 |
+
return JSONResponse(content={"error" : "next to move should be w (white) or b (black)"}, status_code=500)
|
|
|
98 |
|
99 |
+
|
100 |
try:
|
101 |
image_content = await file.read()
|
102 |
if not image_content:
|
|
|
117 |
if "error" in detection_results:
|
118 |
return JSONResponse(content=detection_results, status_code=400)
|
119 |
|
120 |
+
fen = gen_fen(detection_results, perspective, next_to_move)
|
121 |
if not fen:
|
122 |
return JSONResponse(content={"error": "FEN generation failed", "details": "Invalid input data"}, status_code=500)
|
123 |
|
routes/__pycache__/fen_generator.cpython-311.pyc
CHANGED
Binary files a/routes/__pycache__/fen_generator.cpython-311.pyc and b/routes/__pycache__/fen_generator.cpython-311.pyc differ
|
|
routes/fen_generator.py
CHANGED
@@ -108,7 +108,7 @@ def gen_fen(result: dict, p: str, next_to_move : str):
|
|
108 |
fen_rows.append(fen_row) # FIXED: Ensured last row is added
|
109 |
|
110 |
position_fen = "/".join(fen_rows)
|
111 |
-
fen_notation = f"{position_fen}{next_to_move} - - 0 0"
|
112 |
|
113 |
return fen_notation
|
114 |
|
|
|
108 |
fen_rows.append(fen_row) # FIXED: Ensured last row is added
|
109 |
|
110 |
position_fen = "/".join(fen_rows)
|
111 |
+
fen_notation = f"{position_fen} {next_to_move} - - 0 0"
|
112 |
|
113 |
return fen_notation
|
114 |
|