-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebInterface.py
More file actions
38 lines (29 loc) · 1.07 KB
/
webInterface.py
File metadata and controls
38 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import uvicorn
from fastapi import FastAPI, Request, WebSocket, WebSocketDisconnect
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
import main
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def mainpage(request: Request):
return templates.TemplateResponse("index.html", context={"request": request})
@app.post("/analyze")
async def analyze(request: Request):
data = await request.json()
calc_coef = data['mode']['calc_coef']
predict_result = data['mode']['predict_result']
print(predict_result)
coef = []
result = None
if calc_coef:
coef = main.calc_coef(data)
data['coefficients'] = coef
if predict_result:
result = main.predict_result(data)
print({"coef": coef, "result": result})
return {"coef": coef, "result": result}
if __name__ == "__main__":
uvicorn.run("webInterface:app", reload=True)