Spaces:
Runtime error
Runtime error
Download main.py from PageOrg/summaryapi: direct link, hf CLI and curl.
- Browser
- Download file 979 Bytes
-
https://huggingface.co/spaces/PageOrg/summaryapi/resolve/fddef45790dc11b94fb0f367f5e1ea4628ed07eb/main.py
- Command line
-
hf download hf://spaces/PageOrg/summaryapi@fddef45790dc11b94fb0f367f5e1ea4628ed07eb/main.py
-
curl -L -o main.py https://huggingface.co/spaces/PageOrg/summaryapi/resolve/fddef45790dc11b94fb0f367f5e1ea4628ed07eb/main.py
979 Bytes
| 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 != KEY: | |
| 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) | |