Spaces:
Sleeping
Sleeping
Update document_generator_v2.py
Browse files165 unmodified lines166167168169170171466 unmodified lines638639640641165 unmodified linesfrom fastapi import APIRouter, HTTPException, Request, UploadFile, File, Dependsfrom fastapi.responses import StreamingResponsefrom pydantic import BaseModelfrom fastapi_cache.decorator import cacheimport psycopg2from datetime import datetime466 unmodified linesexcept Exception as e:raise HTTPException(status_code=500, detail=f"Failed to retrieve observations: {str(e)}")165 unmodified lines166167168169170171172466 unmodified lines639640641642643644645646647648649650651652653654655656657658659660661662663664665165 unmodified linesfrom fastapi import APIRouter, HTTPException, Request, UploadFile, File, Dependsfrom fastapi.responses import StreamingResponsefrom pydantic import BaseModelfrom fastapi_cache import FastAPICachefrom fastapi_cache.decorator import cacheimport psycopg2from datetime import datetime466 unmodified linesexcept Exception as e:raise HTTPException(status_code=500, detail=f"Failed to retrieve observations: {str(e)}")## TEST CACHEclass CacheItem(BaseModel):key: strvalue: str@router.post("/set-cache")async def set_cache(item: CacheItem):try:# Set the cache with a default expiration of 1 hour (3600 seconds)await FastAPICache.set(item.key, item.value, expire=3600)return {"message": f"Cache set for key: {item.key}"}except Exception as e:raise HTTPException(status_code=500, detail=f"Failed to set cache: {str(e)}")@router.get("/get-cache/{key}")async def get_cache(key: str):try:value = await FastAPICache.get(key)if value is None:raise HTTPException(status_code=404, detail=f"No cache found for key: {key}")return {"key": key, "value": value}except Exception as e:raise HTTPException(status_code=500, detail=f"Failed to get cache: {str(e)}")
document_generator_v2.py+24