Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 3 |
Run locally: HF_TOKEN=hf_... uvicorn app:app --port 7860
|
| 4 |
"""
|
| 5 |
|
|
|
|
| 6 |
import logging
|
| 7 |
import re
|
| 8 |
from datetime import date
|
|
@@ -10,7 +11,7 @@ from pathlib import Path
|
|
| 10 |
|
| 11 |
from fastapi import FastAPI, HTTPException, Request
|
| 12 |
from fastapi.concurrency import run_in_threadpool
|
| 13 |
-
from fastapi.responses import
|
| 14 |
from fastapi.staticfiles import StaticFiles
|
| 15 |
from pydantic import BaseModel, Field
|
| 16 |
|
|
@@ -28,6 +29,12 @@ MIN_DESCRIPTION_CHARS = 20
|
|
| 28 |
app = FastAPI(title="AI Use Check", docs_url=None, redoc_url=None)
|
| 29 |
app.mount("/static", StaticFiles(directory=STATIC), name="static")
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
class Detail(BaseModel):
|
| 33 |
q: int = Field(ge=1, le=7)
|
|
@@ -64,7 +71,8 @@ class ExportRequest(BaseModel):
|
|
| 64 |
|
| 65 |
@app.get("/")
|
| 66 |
def index():
|
| 67 |
-
|
|
|
|
| 68 |
|
| 69 |
|
| 70 |
@app.get("/api/content")
|
|
|
|
| 3 |
Run locally: HF_TOKEN=hf_... uvicorn app:app --port 7860
|
| 4 |
"""
|
| 5 |
|
| 6 |
+
import hashlib
|
| 7 |
import logging
|
| 8 |
import re
|
| 9 |
from datetime import date
|
|
|
|
| 11 |
|
| 12 |
from fastapi import FastAPI, HTTPException, Request
|
| 13 |
from fastapi.concurrency import run_in_threadpool
|
| 14 |
+
from fastapi.responses import HTMLResponse, Response
|
| 15 |
from fastapi.staticfiles import StaticFiles
|
| 16 |
from pydantic import BaseModel, Field
|
| 17 |
|
|
|
|
| 29 |
app = FastAPI(title="AI Use Check", docs_url=None, redoc_url=None)
|
| 30 |
app.mount("/static", StaticFiles(directory=STATIC), name="static")
|
| 31 |
|
| 32 |
+
# The page links to its CSS and JS with ?v=<fingerprint of those files>, so a new upload always gets a
|
| 33 |
+
# new address and no browser or proxy can keep serving an old copy.
|
| 34 |
+
ASSETS = ("styles.css", "catalogue.js", "app.js")
|
| 35 |
+
ASSET_VERSION = hashlib.sha256(b"".join((STATIC / name).read_bytes() for name in ASSETS)).hexdigest()[:10]
|
| 36 |
+
INDEX_HTML = (STATIC / "index.html").read_text(encoding="utf-8").replace("ASSET_VERSION", ASSET_VERSION)
|
| 37 |
+
|
| 38 |
|
| 39 |
class Detail(BaseModel):
|
| 40 |
q: int = Field(ge=1, le=7)
|
|
|
|
| 71 |
|
| 72 |
@app.get("/")
|
| 73 |
def index():
|
| 74 |
+
# no-cache: the browser checks for a new page each time, so it picks up new CSS and JS addresses.
|
| 75 |
+
return HTMLResponse(INDEX_HTML, headers={"Cache-Control": "no-cache"})
|
| 76 |
|
| 77 |
|
| 78 |
@app.get("/api/content")
|