Spaces:
Runtime error
Runtime error
| import uvicorn | |
| from fastapi import FastAPI, Form | |
| from fastapi.responses import JSONResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.templating import Jinja2Templates | |
| from fastapi.requests import Request | |
| from fastapi.responses import HTMLResponse | |
| from dotenv import load_dotenv | |
| app = FastAPI() | |
| app.mount("/static", StaticFiles(directory="static"), name="static") | |
| templates = Jinja2Templates(directory="templates") | |
| async def read_root(request: Request): | |
| return templates.TemplateResponse("index.html", {"request": request}) | |
| async def search( | |
| query: str = Form(...), | |
| top_k: int = Form(5), | |
| protection: bool = Form(False) | |
| ): | |
| # Simulate processing | |
| return JSONResponse({ | |
| "message": "Search response here!", | |
| "query": query, | |
| "top_k": top_k, | |
| "protection": protection | |
| }) | |
| if __name__ == "__main__": | |
| load_dotenv() | |
| uvicorn.run(app, host="0.0.0.0", port=8000) | |