working version

This commit is contained in:
Matteo Rosati
2026-01-20 09:46:21 +01:00
commit 6546853464
11 changed files with 767 additions and 0 deletions

43
app.py Normal file
View File

@@ -0,0 +1,43 @@
import os
import logging
from fastapi import FastAPI, Request, WebSocket
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from main import generate
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
logger = logging.getLogger(__name__)
STATIC_DIR = "static"
TEMPLATES_DIR = "templates"
app = FastAPI()
app.mount(f"/{STATIC_DIR}", StaticFiles(directory=STATIC_DIR), name="static")
templates = Jinja2Templates(directory=os.path.join(STATIC_DIR, TEMPLATES_DIR))
@app.get("/")
async def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
while True:
data = await websocket.receive_text()
logger.info(data)
for chunk in generate(data):
await websocket.send_text(chunk)
await websocket.send_text("<<END>>")