Team Ai
Apppublic

RecursionCat/AbhayaWordLookup

sourceHugging Facemitupdated 7mo agoView on Hugging Face
0likes
main.py45 linesDownload Raw Back to root
1from fastapi import FastAPI, HTTPException2import uvicorn3import os4from utils.language_loader import loadLanguageLookup5from fastapi.middleware.cors import CORSMiddleware6from functools import lru_cache7 8app = FastAPI()9MAX_WORD_LEN = 6410 11app.add_middleware(12    CORSMiddleware,13    allow_origins=["*"],14    allow_credentials=False,15    allow_methods=["*"],16    allow_headers=["*"],17)18 19@app.get('/health')20def health():21    return {"message": "Server Running"}22 23@lru_cache(maxsize=10)24def get_lookup(language: str):25    return loadLanguageLookup(language)26 27@app.get('/getWord/{language}/{word}')28def getWord(language: str, word: str):29    if len(word) > MAX_WORD_LEN:30        raise HTTPException(status_code=400, detail="Word too long")31    try:32        lookup = get_lookup(language.lower())33    except ValueError as e:34        raise HTTPException(status_code=404, detail=str(e))35 36    return lookup.parseResults(word, 0.8)37 38 39if __name__ == "__main__":40    uvicorn.run(41        "main:app",42        host = "0.0.0.0",43        port=int(os.environ.get("PORT", 7860)),44    )45