File size: 961 Bytes
1ccfd50
1b4655e
4adaa35
 
 
cdc5783
0433163
cdc5783
 
 
 
 
 
 
 
 
d57b505
0433163
 
a680719
1b4655e
 
 
1ccfd50
1b4655e
 
4adaa35
df5c837
1ccfd50
 
4adaa35
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
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.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):
    if request.key != KEY:
        return 'Unauthorized'
    pages_summaries, uncached_pages = get_summarize_from_cache(request.pages)
    print(f'processing cached pages: {len(pages_summaries)}, uncached pages: {len(uncached_pages)}')
    background_tasks.add_task(summarize_un_cache_page, uncached_pages)
    print('return')
    return pages_summaries