Skip to content

Commit 57e8e46

Browse files
committed
Add default images
1 parent afb3dbf commit 57e8e46

File tree

7 files changed

+45
-52
lines changed

7 files changed

+45
-52
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ dnn_models/data_preparation/data/combined_data/
88
frontend/node_modules
99
frontend/.next
1010
frontend/out
11+
chessai/frontend-dist
1112
*.egg-info

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ChessAI is a groundbreaking tool that brings together computer vision, chess alg
88

99
## 2. Environment setup
1010

11+
- Requirements: Python 3.9, [Conda](https://docs.conda.io/en/latest/miniconda.html), Node.js 18+.
1112
- Clone this repository.
1213

1314
```bash
@@ -22,6 +23,15 @@ conda activate chessai
2223
pip install -e .
2324
```
2425

26+
- Install Node.js packages and build the frontend.
27+
28+
```bash
29+
cd chessai/frontend
30+
npm install
31+
cd ..
32+
bash build_frontend.sh
33+
```
34+
2535
## 3. Build chess engine
2636

2737
- This project uses [godogpaw](https://github.com/hmgle/godogpaw) as the chess engine.
@@ -38,7 +48,7 @@ go build
3848
## 4. Usage
3949

4050
```bash
41-
ENGINE_PATH="data/engines/godogpaw-macos-arm" python -m chessai.app
51+
ENGINE_PATH="data/engines/godogpaw-macos-arm" python -m chessai.app --run_app
4252
```
4353

4454
Replace `ENGINE_PATH` with the path to the chess engine executable file.

chessai/app.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
def run_window():
4343
from tkinter import Tk
4444
import webview
45-
webview.create_window("chessai", 'http://127.0.0.1:5678', width=1200, height=800)
45+
webview.create_window("ChessAI - Chinese Chess Analyzer", 'http://127.0.0.1:5678', width=1400, height=800)
4646
webview.start()
4747
os._exit(0)
4848

@@ -139,7 +139,7 @@ def main():
139139

140140
# Import these after setting data_root
141141
from chessai.routers import system_monitor, xiangqi
142-
from chessai.utils import extract_frontend_dist, extract_apps
142+
from chessai.utils import extract_frontend_dist
143143
from chessai.database import engine, Base
144144

145145
logging.info("Extracting frontend distribution...")
@@ -149,9 +149,6 @@ def main():
149149
extract_frontend_dist(static_folder)
150150
print(static_folder)
151151

152-
logging.info("Extracting apps...")
153-
apps_folder = os.path.abspath(os.path.join(global_data.data_root, "apps"))
154-
extract_apps(apps_folder)
155152

156153
logging.info("Creating database tables...")
157154
Base.metadata.create_all(bind=engine)

chessai/routers/xiangqi.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,61 @@
44
import cv2
55

66

7+
DEFAULT_VISUALIZATION_FRAME = cv2.imread(
8+
"data/default_visualization_frame.jpeg"
9+
)
10+
711
router = APIRouter(
812
prefix="/api/xiangqi",
913
tags=["Run services"],
1014
)
1115

16+
1217
def encode_image(image):
1318
_, buffer = cv2.imencode(".jpg", image)
1419
return buffer.tobytes()
1520

21+
1622
@router.get("/original_frame", response_class=Response)
1723
async def original_frame():
1824
with globals.frame_lock:
25+
frame = None
1926
if globals.original_frame is None:
20-
return ""
27+
frame = DEFAULT_VISUALIZATION_FRAME
2128
else:
22-
encoded_frame = encode_image(globals.original_frame)
23-
return Response(
24-
content=encoded_frame,
25-
media_type="image/jpg",
26-
)
29+
frame = globals.original_frame
30+
encoded_frame = encode_image(frame)
31+
return Response(
32+
content=encoded_frame,
33+
media_type="image/jpg",
34+
)
2735

2836

2937
@router.get("/debug_frame", response_class=Response)
3038
async def debug_frame():
3139
with globals.frame_lock:
40+
frame = None
3241
if globals.debug_frame is None:
33-
return ""
42+
frame = DEFAULT_VISUALIZATION_FRAME
3443
else:
35-
encoded_frame = encode_image(globals.debug_frame)
36-
return Response(
37-
content=encoded_frame,
38-
media_type="image/jpg",
39-
)
44+
frame = globals.debug_frame
45+
encoded_frame = encode_image(frame)
46+
return Response(
47+
content=encoded_frame,
48+
media_type="image/jpg",
49+
)
4050

4151

4252
@router.get("/visualization_frame", response_class=Response)
4353
async def visualization_frame():
4454
with globals.frame_lock:
55+
frame = None
4556
if globals.visualization_frame is None:
46-
return ""
57+
frame = DEFAULT_VISUALIZATION_FRAME
4758
else:
48-
encoded_frame = encode_image(globals.visualization_frame)
49-
return Response(
50-
content=encoded_frame,
51-
media_type="image/jpg",
52-
)
53-
59+
frame = globals.visualization_frame
60+
encoded_frame = encode_image(frame)
61+
return Response(
62+
content=encoded_frame,
63+
media_type="image/jpg",
64+
)

chessai/utils.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
import platform
77
import shutil
88
import subprocess
9-
import tempfile
10-
119
import pkg_resources
12-
import requests
10+
1311

1412
def open_file(path):
1513
"""
@@ -45,28 +43,6 @@ def extract_frontend_dist(static_folder):
4543
return
4644

4745

48-
def extract_apps(static_folder):
49-
"""
50-
Extract folder apps from package chessai
51-
and put it in the same static folder for serving
52-
"""
53-
if os.path.exists(static_folder):
54-
logging.info(f"Refreshing {static_folder}...")
55-
shutil.rmtree(static_folder, ignore_errors=True)
56-
apps_folder = pkg_resources.resource_filename("chessai", "apps")
57-
if os.path.exists(apps_folder):
58-
pathlib.Path(static_folder).parent.mkdir(parents=True, exist_ok=True)
59-
shutil.copytree(apps_folder, static_folder)
60-
if not os.path.exists(static_folder):
61-
logging.warning("apps not found in package chessai")
62-
pathlib.Path(static_folder).mkdir(parents=True, exist_ok=True)
63-
with open(os.path.join(static_folder, "index.html"), "w") as f:
64-
f.write(
65-
"<b>apps</b> not found in package chessai. Please run: <code>bash build_apps.sh</code>"
66-
)
67-
return
68-
69-
7046
def draw_message_box(width, height, message):
7147
"""Draws a message box with the given width, height and message"""
7248
message_frame = np.zeros((height, width, 3), dtype=np.uint8)

data/default_visualization_frame.jpeg

70.6 KB
Loading

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ def get_long_description():
7878
"chessai": [
7979
"chessai/frontend-dist/**/*",
8080
"chessai/frontend-dist/*",
81-
"chessai/apps/**/*",
82-
"chessai/apps/*",
8381
]
8482
},
8583
include_package_data=True,

0 commit comments

Comments
 (0)