A simple REST API to identify language of given text
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Harish Karumuthil 1dee8b70ff Added generated files 3 years ago
generated Added generated files 3 years ago
.gitignore Added tests and documentation 3 years ago
Readme.design.md Added tests and documentation 3 years ago
Readme.md Added tests and documentation 3 years ago
eval_accuracy.py Separating accuracy evaluation code 3 years ago
language_detector.py Initial commit 3 years ago
requirements.txt Initial commit 3 years ago
run-server.sh Initial commit 3 years ago
server.py Added tests and documentation 3 years ago
test.py Separating accuracy evaluation code 3 years ago

Readme.md

Prerequisite

  • python3

Installation

To avoid local package pollution, it would be better to create virtual environment for this installation

pip3 install virtualenv

# Create a virtual env in ./venv directory
virtualenv ./venv

# Activate virtualenv
. ./venv/bin/activate

Then install dependencies

pip3 install -r ./requirements.txt

Running server

./run-server.sh 

# INFO:language-detector:Training model ...
# INFO:language-detector:Downloading dataset from url ...
# INFO:language-detector:Saved dataset to cache ...
# INFO:language-detector:Training complete. Feature count: 6109840
# INFO:language-detector:saved model lang-detect-MNB.pkl
# INFO:     Started server process [1780455]
# INFO:uvicorn.error:Started server process [1780455]
# INFO:     Waiting for application startup.
# INFO:uvicorn.error:Waiting for application startup.
# INFO:     Application startup complete.
# INFO:uvicorn.error:Application startup complete.
# INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
# INFO:uvicorn.error:Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

checking API response from terminal

curl -X POST  -H "Accept: application/json"  -H "Content-Type: application/json"  "http://localhost:8000/api/language/predict"  -d '{"text": "Hello how old are you"}'

# {"lang": "English", "score": 0.9998260997236165}