Spaces:
Runtime error
Runtime error
File size: 1,047 Bytes
4adaa35 1b4655e d57b505 1b4655e 4adaa35 cdc5783 0433163 cdc5783 8327181 cdc5783 d57b505 0433163 a680719 1b4655e 4adaa35 df5c837 4adaa35 b903ee4 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 |
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(max_workers=5)
@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'
pages_summaries, uncached_pages = get_summarize_from_cache(request.pages)
print(f'processing cached pages: {len(pages_summaries)}, uncached pages: {len(uncached_pages)}')
loop = asyncio.get_event_loop()
await loop.run_in_executor(executor, summarize_un_cache_page, uncached_pages)
return pages_summaries
|