Spaces:
Sleeping
Sleeping
Download app/api.py from deepset/post-conference-report: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/deepset/post-conference-report/resolve/main/app/api.py
- Command line
-
hf download hf://spaces/deepset/post-conference-report/app/api.py
-
curl -L -o api.py https://huggingface.co/spaces/deepset/post-conference-report/resolve/main/app/api.py
1.06 kB
| import logging | |
| from collections.abc import AsyncIterable | |
| from pathlib import Path | |
| from fastapi import FastAPI | |
| from fastapi.responses import FileResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from app.agent import MODEL, run_agent | |
| from app.models import AgentRequest, TextChunk | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format="%(asctime)s %(levelname)s %(name)s: %(message)s", | |
| ) | |
| logger = logging.getLogger(__name__) | |
| app = FastAPI() | |
| _STATIC = Path(__file__).parent / "static" | |
| app.mount("/static", StaticFiles(directory=_STATIC), name="static") | |
| async def config(): | |
| return {"model": MODEL} | |
| async def index() -> FileResponse: | |
| return FileResponse(_STATIC / "index.html") | |
| async def handle_agent_call(request: AgentRequest) -> AsyncIterable[TextChunk]: | |
| try: | |
| async for chunk in run_agent(request.input): | |
| yield chunk | |
| except Exception as exc: | |
| logger.exception("Agent error during streaming") | |
| yield TextChunk(type="error", content=str(exc)) | |