-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (50 loc) · 1.66 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pathlib
import random
from collections import OrderedDict
import polars as pl
from faker import Faker
# import pandas as pd
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
# FastAPI
app = FastAPI()
# Faker
locales = OrderedDict(
[
("en", 1),
]
)
fake = Faker(locales)
# Static assets path
BASE_DIR = pathlib.Path.cwd()
app.mount("/static", StaticFiles(directory=BASE_DIR / "ui" / "static"), name="static")
templates = Jinja2Templates(directory=BASE_DIR / "ui" / "templates")
@app.get("/", response_class=HTMLResponse)
async def read_item(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.get("/tab1", response_class=HTMLResponse)
async def tab1(request: Request):
return templates.TemplateResponse("tab1.html", {"request": request})
@app.get("/tab2", response_class=HTMLResponse)
async def tab2(request: Request):
people = [
{
"Name": fake.name(),
"Age": random.randint(20, 70),
"Address": fake.address(),
}
for _ in range(50)
]
# df = pd.DataFrame(people)
# return templates.TemplateResponse(
# "tab2.html", {"request": request, "columns": df.columns, "data": df.to_dict("records")}
# )
df = pl.DataFrame(people)
return templates.TemplateResponse(
"tab2.html", {"request": request, "columns": df.columns, "data": df.to_dicts()}
)
@app.get("/tab3", response_class=HTMLResponse)
async def tab3(request: Request):
return templates.TemplateResponse("tab3.html", {"request": request})