Paweł Łaba commited on
Commit
c420a2a
·
1 Parent(s): 9616708

zmiany w index

Browse files
Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -1,5 +1,5 @@
1
- from fastapi import FastAPI, HTTPException, Request
2
- from fastapi.responses import JSONResponse, HTMLResponse
3
  from fastapi.staticfiles import StaticFiles
4
  import numpy as np
5
  from tensorflow import keras
@@ -8,10 +8,9 @@ import os
8
 
9
  app = FastAPI()
10
 
11
- # Obsługa plików statycznych
12
  app.mount("/public", StaticFiles(directory="public"), name="public")
13
 
14
-
15
  @app.get("/", response_class=HTMLResponse)
16
  async def read_root():
17
  """Wyświetla plik index.html"""
@@ -54,14 +53,12 @@ class TicTacToeAI:
54
  # Inicjalizacja AI
55
  ai = TicTacToeAI()
56
 
57
-
58
  @app.post("/move")
59
- async def get_move(request: Request):
60
  """
61
  Endpoint do wykonania ruchu AI
62
  """
63
  try:
64
- data = await request.json()
65
  board = data.get("board")
66
 
67
  if not board:
@@ -72,18 +69,16 @@ async def get_move(request: Request):
72
 
73
  move = ai.get_move(board)
74
 
75
- return JSONResponse(content={"status": "success", "move": move})
76
  except Exception as e:
77
  raise HTTPException(status_code=500, detail=str(e))
78
 
79
-
80
  @app.post("/game")
81
- async def add_game(request: Request):
82
  """
83
  Endpoint do dodania gry do pliku
84
  """
85
  try:
86
- data = await request.json()
87
  board = data.get("board")
88
  win = data.get("win")
89
 
@@ -104,7 +99,7 @@ async def add_game(request: Request):
104
  with open("gry.json", "w") as file:
105
  json.dump(games_data, file)
106
 
107
- return JSONResponse(content={"status": "success"})
108
  except Exception as e:
109
  raise HTTPException(status_code=500, detail=str(e))
110
 
@@ -112,10 +107,8 @@ async def add_game(request: Request):
112
  @app.get("/status")
113
  async def get_status():
114
  """Sprawdza status modelu"""
115
- return JSONResponse(
116
- content={
117
- "status": "success",
118
- "model_loaded": ai.model is not None,
119
- "model_path": ai.model_path,
120
- }
121
- )
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from fastapi.responses import HTMLResponse
3
  from fastapi.staticfiles import StaticFiles
4
  import numpy as np
5
  from tensorflow import keras
 
8
 
9
  app = FastAPI()
10
 
11
+ # Obsługa katalogu publicznego
12
  app.mount("/public", StaticFiles(directory="public"), name="public")
13
 
 
14
  @app.get("/", response_class=HTMLResponse)
15
  async def read_root():
16
  """Wyświetla plik index.html"""
 
53
  # Inicjalizacja AI
54
  ai = TicTacToeAI()
55
 
 
56
  @app.post("/move")
57
+ async def get_move(data: dict):
58
  """
59
  Endpoint do wykonania ruchu AI
60
  """
61
  try:
 
62
  board = data.get("board")
63
 
64
  if not board:
 
69
 
70
  move = ai.get_move(board)
71
 
72
+ return {"status": "success", "move": move}
73
  except Exception as e:
74
  raise HTTPException(status_code=500, detail=str(e))
75
 
 
76
  @app.post("/game")
77
+ async def add_game(data: dict):
78
  """
79
  Endpoint do dodania gry do pliku
80
  """
81
  try:
 
82
  board = data.get("board")
83
  win = data.get("win")
84
 
 
99
  with open("gry.json", "w") as file:
100
  json.dump(games_data, file)
101
 
102
+ return {"status": "success"}
103
  except Exception as e:
104
  raise HTTPException(status_code=500, detail=str(e))
105
 
 
107
  @app.get("/status")
108
  async def get_status():
109
  """Sprawdza status modelu"""
110
+ return {
111
+ "status": "success",
112
+ "model_loaded": ai.model is not None,
113
+ "model_path": ai.model_path,
114
+ }