Paweł Łaba
commited on
Commit
·
d7b060a
1
Parent(s):
7db730a
zmiany
Browse files
app.py
CHANGED
@@ -6,28 +6,6 @@ from tensorflow import keras
|
|
6 |
import json
|
7 |
import os
|
8 |
|
9 |
-
|
10 |
-
# Ustawienie prefiksu aplikacji
|
11 |
-
app = FastAPI(root_path="/spaces/labapawel/tictactoe")
|
12 |
-
|
13 |
-
@app.on_event("startup")
|
14 |
-
async def print_routes():
|
15 |
-
for route in app.routes:
|
16 |
-
print(f"Path: {route.path}, Name: {route.name}, Methods: {route.methods}")
|
17 |
-
|
18 |
-
# Montowanie katalogu publicznego
|
19 |
-
app.mount("/static", StaticFiles(directory="public"), name="static")
|
20 |
-
|
21 |
-
@app.get("/", response_class=HTMLResponse)
|
22 |
-
async def read_root():
|
23 |
-
try:
|
24 |
-
with open("public/index.html", "r") as file:
|
25 |
-
return HTMLResponse(content=file.read(), status_code=200)
|
26 |
-
except FileNotFoundError:
|
27 |
-
return HTMLResponse(content="Plik index.html nie został znaleziony", status_code=404)
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
class TicTacToeAI:
|
32 |
def __init__(self, model_path="model/model.keras"):
|
33 |
self.model_path = model_path
|
@@ -60,6 +38,35 @@ class TicTacToeAI:
|
|
60 |
# Inicjalizacja AI
|
61 |
ai = TicTacToeAI()
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
@app.post("/move")
|
64 |
async def get_move(data: dict):
|
65 |
"""
|
|
|
6 |
import json
|
7 |
import os
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
class TicTacToeAI:
|
10 |
def __init__(self, model_path="model/model.keras"):
|
11 |
self.model_path = model_path
|
|
|
38 |
# Inicjalizacja AI
|
39 |
ai = TicTacToeAI()
|
40 |
|
41 |
+
|
42 |
+
|
43 |
+
# Ustawienie prefiksu aplikacji
|
44 |
+
app = FastAPI(root_path="/spaces/labapawel/tictactoe")
|
45 |
+
|
46 |
+
@app.on_event("startup")
|
47 |
+
async def print_routes():
|
48 |
+
"""Wyświetla wszystkie zarejestrowane trasy"""
|
49 |
+
for route in app.routes:
|
50 |
+
if hasattr(route, "methods"): # Jeśli trasa obsługuje metody HTTP
|
51 |
+
print(f"Path: {route.path}, Name: {route.name}, Methods: {route.methods}")
|
52 |
+
elif isinstance(route, Mount): # Jeśli to katalog statyczny
|
53 |
+
print(f"Mounted Path: {route.path}, Name: {route.name}, App: {route.app}")
|
54 |
+
else: # Inny typ trasy
|
55 |
+
print(f"Other Route Path: {route.path}, Name: {route.name}")
|
56 |
+
|
57 |
+
# Montowanie katalogu publicznego
|
58 |
+
app.mount("/static", StaticFiles(directory="public"), name="static")
|
59 |
+
|
60 |
+
@app.get("/", response_class=HTMLResponse)
|
61 |
+
async def read_root():
|
62 |
+
try:
|
63 |
+
with open("public/index.html", "r") as file:
|
64 |
+
return HTMLResponse(content=file.read(), status_code=200)
|
65 |
+
except FileNotFoundError:
|
66 |
+
return HTMLResponse(content="Plik index.html nie został znaleziony", status_code=404)
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
@app.post("/move")
|
71 |
async def get_move(data: dict):
|
72 |
"""
|