Spaces:
Runtime error
Runtime error
File size: 1,103 Bytes
724f703 1ccfd50 1b4655e 4adaa35 d5f14ef 4adaa35 cdc5783 0433163 cdc5783 d57b505 0433163 a680719 1b4655e 1ccfd50 724f703 1b4655e 4adaa35 1ccfd50 4adaa35 d5f14ef |
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 |
import os
from fastapi import FastAPI, BackgroundTasks
from utils.cache_layer import get_summarize_from_cache, summarize_un_cache_page
from utils.data_proto import SummaryReq, SummariesReq
from utils.logging import read_last_n_logs
from utils.summary_utils import summarize
KEY = 'J9l#K4wP5h@2'
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.post("/summary/")
async def summary(request: SummaryReq):
if request.key != KEY:
return 'Unauthorized'
return summarize(request.id, request.text)
@app.post("/summaries/")
async def summaries(background_tasks: BackgroundTasks, request: SummariesReq):
print(os.environ.get("AccessKey"))
print('====================')
print(request)
print('====================')
if request.key != KEY:
return 'Unauthorized'
pages_summaries, uncached_pages = get_summarize_from_cache(request.pages)
background_tasks.add_task(summarize_un_cache_page, uncached_pages)
return pages_summaries
@app.get("/logs/")
async def logs(n: int = 100):
return read_last_n_logs(n)
|