Download app.py from pythainlp/api: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/pythainlp/api/resolve/main/app.py
- Command line
-
hf download hf://spaces/pythainlp/api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/pythainlp/api/resolve/main/app.py
1.55 kB
| from fastapi import Depends, FastAPI, Header, HTTPException | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.responses import RedirectResponse | |
| from routers import tokenize, soundex, util, spell | |
| from fastapi_mcp import FastApiMCP | |
| import pythainlp | |
| DESC_TEXT = """# PyThaiNLP API | |
| PyThaiNLP API | |
| """ | |
| app = FastAPI( | |
| title='PyThaiNLP API', | |
| description=DESC_TEXT, | |
| # summary="Deadpool's favorite app. Nuff said.", | |
| version="0.0.1", | |
| debug=False, | |
| # terms_of_service="http://example.com/terms/", | |
| # contact={ | |
| # "name": "Deadpoolio the Amazing", | |
| # "url": "http://x-force.example.com/contact/", | |
| # "email": "dp@x-force.example.com", | |
| # }, | |
| license_info={ | |
| "name": "Apache 2.0", | |
| "url": "https://www.apache.org/licenses/LICENSE-2.0.html", | |
| }, | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| def index(): | |
| response = RedirectResponse(url='/docs') | |
| return response | |
| def version(): | |
| """ | |
| Get PyThaiNLP Version | |
| """ | |
| return {"version": pythainlp.__version__} | |
| app.include_router(tokenize.router, prefix="/tokenize", tags=["Tokenize"]) | |
| app.include_router(soundex.router, prefix="/soundex", tags=["Soundex"]) | |
| app.include_router(spell.router, prefix="/spell", tags=["Spell"]) | |
| app.include_router(util.router, prefix="/util", tags=["Util"]) | |
| mcp = FastApiMCP(app) | |
| # Mount the MCP server directly to your FastAPI app | |
| mcp.mount() |