Spaces:
Runtime error
Runtime error
| 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() | |
| async def root(): | |
| return {"message": "Hello World"} | |
| async def summary(request: SummaryReq): | |
| if request.key != KEY: | |
| return 'Unauthorized' | |
| return summarize(request.id, request.text) | |
| 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) | |
| loop = asyncio.get_event_loop() | |
| await loop.run_in_executor(executor, summarize_un_cache_page, uncached_pages) | |
| return pages_summaries | |