Spaces:
Sleeping
Sleeping
JerameeUC
12 Commit PyTest Working But Failing for some. The individual sections need to be completed to fix.
0c4f0e3 | # /agenticcore/web_agentic.py | |
| from fastapi import FastAPI, Query, Request | |
| from fastapi.responses import HTMLResponse, JSONResponse, FileResponse, Response | |
| from fastapi.staticfiles import StaticFiles # <-- ADD THIS | |
| from agenticcore.chatbot.services import ChatBot | |
| import pathlib | |
| import os | |
| app = FastAPI(title="AgenticCore Web UI") | |
| # 1) Simple HTML form at / | |
| def index(): | |
| return """ | |
| <head> | |
| <link rel="icon" type="image/png" href="/static/favicon.png"> | |
| <title>AgenticCore</title> | |
| </head> | |
| <form action="/agentic" method="get" style="padding:16px;"> | |
| <input type="text" name="msg" placeholder="Type a message" style="width:300px"> | |
| <input type="submit" value="Send"> | |
| </form> | |
| """ | |
| # 2) Agentic endpoint | |
| def run_agentic(msg: str = Query(..., description="Message to send to ChatBot")): | |
| bot = ChatBot() | |
| return bot.reply(msg) | |
| # --- Static + favicon setup --- | |
| # TIP: we're inside <repo>/agenticcore/web_agentic.py | |
| # repo root = parents[1] | |
| repo_root = pathlib.Path(__file__).resolve().parents[1] | |
| # Put static assets under app/assets/html | |
| assets_path = repo_root / "app" / "assets" / "html" | |
| assets_path_str = str(assets_path) | |
| # Mount /static so /static/favicon.png works | |
| app.mount("/static", StaticFiles(directory=assets_path_str), name="static") | |
| # Serve /favicon.ico (browsers request this path) | |
| async def favicon(): | |
| ico = assets_path / "favicon.ico" | |
| png = assets_path / "favicon.png" | |
| if ico.exists(): | |
| return FileResponse(str(ico), media_type="image/x-icon") | |
| if png.exists(): | |
| return FileResponse(str(png), media_type="image/png") | |
| # Graceful fallback if no icon present | |
| return Response(status_code=204) | |
| def health(): | |
| return {"status": "ok"} | |
| async def chatbot_message(request: Request): | |
| payload = await request.json() | |
| msg = str(payload.get("message", "")).strip() or "help" | |
| return ChatBot().reply(msg) | |