Spaces:
Running
Running
Commit
·
4ee699d
1
Parent(s):
5395b71
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,6 +25,18 @@ def get_puzzle_positions(fen, moves_uci):
|
|
| 25 |
|
| 26 |
return positions
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
app = FastAPI()
|
| 29 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 30 |
templates = Jinja2Templates(directory="templates")
|
|
|
|
| 25 |
|
| 26 |
return positions
|
| 27 |
|
| 28 |
+
def load_index(path='chess_index.pkl'):
|
| 29 |
+
with open(path, 'rb') as f: data = pickle.load(f)
|
| 30 |
+
return data['index'], data['metadata']
|
| 31 |
+
|
| 32 |
+
def query_positions(index, metadata, query_tokens):
|
| 33 |
+
result = index[query_tokens[0]].copy() if query_tokens[0] in index else BitMap()
|
| 34 |
+
for token in query_tokens[1:]:
|
| 35 |
+
if token in index: result &= index[token]
|
| 36 |
+
else: return BitMap()
|
| 37 |
+
|
| 38 |
+
return [(pos_id, metadata[pos_id]) for pos_id in result]
|
| 39 |
+
|
| 40 |
app = FastAPI()
|
| 41 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 42 |
templates = Jinja2Templates(directory="templates")
|