Spaces:
Runtime error
Runtime error
| 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 | |
| app = FastAPI() | |
| async def root(): | |
| return {"message": "Hello World"} | |
| async def summary(request: SummaryReq): | |
| if request.key != os.environ.get("AccessKey"): | |
| return 'Unauthorized' | |
| return summarize(request.id, request.text) | |
| async def summaries(background_tasks: BackgroundTasks, request: SummariesReq): | |
| if request.key != os.environ.get("AccessKey"): | |
| 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 | |
| async def logs(n: int = 100): | |
| return read_last_n_logs(n) | |