Spaces:
Sleeping
Sleeping
from typing import Dict, List, Union | |
from time import gmtime, strftime | |
from fastapi import FastAPI | |
from fastapi.staticfiles import StaticFiles | |
from fastapi.responses import FileResponse | |
from modules.details import Details, rand_details | |
from modules.dataset import get_image, get_stats | |
app = FastAPI(docs_url=None, redoc_url=None) | |
app.mount("/static", StaticFiles(directory="static"), name="static") | |
card_logs = [] | |
def index() -> FileResponse: | |
return FileResponse(path="static/index.html", media_type="text/html") | |
def new_card() -> Dict[str, Union[Details, str]]: | |
card_logs.append(strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())) | |
details: Details = rand_details() | |
return { | |
"details": details, | |
"image": get_image(details["energy_type"]), | |
} | |
def stats() -> Dict[str, Union[int, object]]: | |
return {**get_stats(), **{"cards_served": len(card_logs)}} | |
def logs() -> List[str]: | |
return card_logs | |