Spaces:
Sleeping
Sleeping
Download api/main.py from Sujith2121/Semantic-search-cache: direct link, hf CLI and curl.
- Browser
- Download file 704 Bytes
-
https://huggingface.co/spaces/Sujith2121/Semantic-search-cache/resolve/main/api/main.py
- Command line
-
hf download hf://spaces/Sujith2121/Semantic-search-cache/api/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Sujith2121/Semantic-search-cache/resolve/main/api/main.py
704 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| import sys | |
| import os | |
| # allow importing from src | |
| sys.path.append(os.path.abspath("src")) | |
| from query_engine import QueryEngine | |
| app = FastAPI() | |
| engine = QueryEngine() | |
| class QueryRequest(BaseModel): | |
| query: str | |
| top_k: int = 5 | |
| def home(): | |
| return {"message": "Semantic Search Cache API running"} | |
| def search(request: QueryRequest): | |
| result = engine.search(request.query, request.top_k) | |
| return result | |
| def cache_stats(): | |
| return engine.cache_stats() | |
| def clear_cache(): | |
| engine.clear_cache() | |
| return {"message": "Cache cleared"} |