Spaces:
Running
Running
fixed filtering by moves
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import io
|
2 |
-
import random
|
3 |
|
4 |
import chess
|
5 |
import chess.pgn
|
@@ -7,14 +6,15 @@ import chess.svg
|
|
7 |
import streamlit as st
|
8 |
from datasets import load_dataset
|
9 |
|
10 |
-
|
11 |
-
st.set_page_config(page_title="Chess Openings Trainer", page_icon="♖")
|
12 |
|
13 |
|
14 |
@st.cache_data
|
15 |
def load_data():
|
16 |
ds = load_dataset("Lichess/chess-openings", split="train")
|
17 |
df = ds.to_pandas()
|
|
|
|
|
18 |
return df
|
19 |
|
20 |
|
@@ -37,7 +37,7 @@ if data.empty:
|
|
37 |
st.stop()
|
38 |
|
39 |
# App layout
|
40 |
-
st.title("Chess Openings
|
41 |
|
42 |
with st.sidebar:
|
43 |
st.header("Settings")
|
@@ -46,15 +46,17 @@ with st.sidebar:
|
|
46 |
min_moves, max_moves = st.slider(
|
47 |
"Select range of moves:", min_value=1, max_value=18, value=(1, 18), step=1
|
48 |
)
|
|
|
49 |
|
50 |
# Hide next moves checkbox
|
51 |
hide_next_moves = st.checkbox("Hide next moves", value=True)
|
52 |
|
53 |
# Filter the data based on the min and max number of moves
|
54 |
filtered_data = data[
|
55 |
-
(data["pgn"].str.count("
|
56 |
-
& (data["pgn"].str.count("
|
57 |
]
|
|
|
58 |
|
59 |
if filtered_data.empty:
|
60 |
st.error(
|
@@ -134,7 +136,7 @@ col1, col2 = st.columns([3, 1])
|
|
134 |
|
135 |
with col1:
|
136 |
if st.session_state.current_opening:
|
137 |
-
st.
|
138 |
|
139 |
col_prev, col_next, right_col = st.columns([1, 1, 1])
|
140 |
|
|
|
1 |
import io
|
|
|
2 |
|
3 |
import chess
|
4 |
import chess.pgn
|
|
|
6 |
import streamlit as st
|
7 |
from datasets import load_dataset
|
8 |
|
9 |
+
st.set_page_config(page_title="Practice Chess Openings", page_icon="♖")
|
|
|
10 |
|
11 |
|
12 |
@st.cache_data
|
13 |
def load_data():
|
14 |
ds = load_dataset("Lichess/chess-openings", split="train")
|
15 |
df = ds.to_pandas()
|
16 |
+
print(f"Total openings: {len(df)}")
|
17 |
+
print(df["pgn"].head())
|
18 |
return df
|
19 |
|
20 |
|
|
|
37 |
st.stop()
|
38 |
|
39 |
# App layout
|
40 |
+
st.title("Practice Chess Openings")
|
41 |
|
42 |
with st.sidebar:
|
43 |
st.header("Settings")
|
|
|
46 |
min_moves, max_moves = st.slider(
|
47 |
"Select range of moves:", min_value=1, max_value=18, value=(1, 18), step=1
|
48 |
)
|
49 |
+
print(f"{min_moves=}, {max_moves=}")
|
50 |
|
51 |
# Hide next moves checkbox
|
52 |
hide_next_moves = st.checkbox("Hide next moves", value=True)
|
53 |
|
54 |
# Filter the data based on the min and max number of moves
|
55 |
filtered_data = data[
|
56 |
+
(data["pgn"].str.count("\.") >= min_moves)
|
57 |
+
& (data["pgn"].str.count("\.") <= max_moves)
|
58 |
]
|
59 |
+
print(f"Total openings after filtering: {len(filtered_data)}")
|
60 |
|
61 |
if filtered_data.empty:
|
62 |
st.error(
|
|
|
136 |
|
137 |
with col1:
|
138 |
if st.session_state.current_opening:
|
139 |
+
st.subheader(f":blue[{st.session_state.current_opening}]")
|
140 |
|
141 |
col_prev, col_next, right_col = st.columns([1, 1, 1])
|
142 |
|