Spaces:
Runtime error
Runtime error
File size: 1,030 Bytes
4adaa35 1b4655e d57b505 1b4655e 4adaa35 cdc5783 0433163 cdc5783 4adaa35 cdc5783 d57b505 0433163 a680719 1b4655e b3b4ef3 4adaa35 7b57fb0 4adaa35 cb6e9b2 7b57fb0 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 33 34 35 36 37 38 |
import asyncio
from concurrent.futures import ThreadPoolExecutor
from fastapi import FastAPI
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()
executor = ThreadPoolExecutor()
@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(request: SummariesReq):
if request.key != KEY:
return 'Unauthorized'
print(f'process pages length: {len(request.pages)}')
pages_summaries, uncached_pages = get_summarize_from_cache(request.pages)
print(uncached_pages)
loop = asyncio.get_event_loop()
loop.run_in_executor(executor, summarize_un_cache_page, uncached_pages)
print('return')
return pages_summaries
|