| |
|
|
| from fastapi import FastAPI |
| from fastapi.middleware.cors import CORSMiddleware |
| from fastapi.responses import HTMLResponse |
| from fastapi.staticfiles import StaticFiles |
| from huggingface_hub import login |
| from config import settings |
| from routers import tool_bpy_doc, tool_gpu_checker, tool_find_related, tool_wiki_search, tool_calls |
|
|
| login(settings.huggingface_key) |
|
|
| app = FastAPI(openapi_url="/api/v1/openapi.json", |
| docs_url="/api/v1/docs") |
|
|
| app.add_middleware( |
| CORSMiddleware, |
| allow_origins=["https://projects.blender.org"], |
| allow_methods=["GET", "POST"], |
| allow_headers=["Authorization", "Content-Type"], |
| allow_credentials=True, |
| ) |
|
|
| app.include_router( |
| tool_bpy_doc.router, prefix="/api/v1", tags=["Tools"]) |
|
|
| app.include_router( |
| tool_gpu_checker.router, prefix="/api/v1", tags=["Tools"]) |
|
|
| app.include_router( |
| tool_find_related.router, prefix="/api/v1", tags=["Tools"]) |
|
|
| app.include_router( |
| tool_wiki_search.router, prefix="/api/v1", tags=["Tools"]) |
|
|
| app.include_router( |
| tool_calls.router, prefix="/api/v1", tags=["Function Calls"]) |
|
|
|
|
| @app.get("/", response_class=HTMLResponse) |
| async def root(): |
| return """ |
| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>My Endpoints</title> |
| </head> |
| <body> |
| <h1>Welcome to @mano-wii API</h1> |
| <p>Click the button below to access the documentation:</p> |
| <a href="/api/v1/docs" style="text-decoration: none;"> |
| <button style="padding: 10px 20px; background-color: #007BFF; color: #fff; border: none; cursor: pointer;">Go to Documentation</button> |
| </a> |
| </body> |
| </html> |
| """ |
|
|
| app.mount("/api/v1/static", StaticFiles(directory="static"), name="static") |
|
|