-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
39 lines (28 loc) · 867 Bytes
/
main.py
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
39
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
# Server Imports.
from backend.score import compute_score
app = FastAPI()
templates = Jinja2Templates(directory="frontend/templates")
app.mount("/static", StaticFiles(directory="frontend/static"), name="static")
@app.get("/")
def homepage(request: Request):
return templates.TemplateResponse("homepage.html", context={
"request": request
})
# Validating user input.
class UserInput(BaseModel):
user_input: str
@app.post("/report")
def generate_report(user_input: UserInput):
"""
Generate Readability Report.
"""
user_input = user_input.user_input
scores, stats = compute_score(user_input)
return {
"scores": scores,
"stats": stats
}