Spaces:
Runtime error
Runtime error
Download app.py from freelancerrhinobi/chatbot1: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/spaces/freelancerrhinobi/chatbot1/resolve/main/app.py
- Command line
-
hf download hf://spaces/freelancerrhinobi/chatbot1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/freelancerrhinobi/chatbot1/resolve/main/app.py
1.68 kB
| from fastapi import FastAPI, APIRouter | |
| from pydantic import BaseModel | |
| # Import adhd_gemini function from adhd_gemini module | |
| from adhd_gemini import adhd_gemini | |
| # Create FastAPI app instance | |
| app = FastAPI() | |
| # Define a router for API documentation | |
| router = APIRouter() | |
| # Define request/response models | |
| class QueryIn(BaseModel): | |
| query: str | |
| class QueryOut(BaseModel): | |
| response: str | |
| # Define your endpoints | |
| async def adhd_gemini_func(q: QueryIn): | |
| """ | |
| Endpoint to receive a query and return the response. | |
| """ | |
| response = adhd_gemini(query=q.query) | |
| return QueryOut(response=response) | |
| async def adhd_openai_func(q: QueryIn): | |
| """ | |
| Endpoint to receive a query and return the response. | |
| """ | |
| response = adhd_gemini(query=q.query) | |
| return QueryOut(response=response) | |
| # Add a default endpoint to display available endpoints | |
| async def root(): | |
| return {"message": "Welcome to the chatbot API. Available endpoints:", | |
| "endpoints": [ | |
| "/adhd_gemini/ - POST method", | |
| "/adhd_openai/ - POST method" | |
| ]} | |
| # Include the router into the main app | |
| app.include_router(router) | |
| # Optionally, generate OpenAPI schema | |
| async def get_openapi(): | |
| return app.openapi() | |
| # This is optional, if you want to see the generated OpenAPI schema in Swagger UI | |
| async def get_docs(): | |
| return app.openapi_schema() | |
| # This is also optional, for using Redoc | |
| async def redoc(): | |
| return app.openapi_schema(url="/openapi.json") | |