File size: 1,485 Bytes
075c27b
 
5657691
075c27b
5657691
 
 
 
 
 
075c27b
 
 
 
 
 
 
 
5657691
075c27b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5657691
075c27b
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os

# print("Installing dependencies...")

# os.system("git clone https://github.com/PrithivirajDamodaran/neuspell.git")
# os.chdir('neuspell')
# os.system('pip install -e .[elmo]')
# os.system('pip install -e .[spacy]')

print("Loading Spacy Model...")
os.system("python -m spacy download en_core_web_sm")

import neuspell
from neuspell import BertsclstmChecker, ElmosclstmChecker, CnnlstmChecker
bl_checker = BertsclstmChecker()
el_checker = ElmosclstmChecker()
cl_checker = CnnlstmChecker()

print("Loading Neuspell Models...")
bl_checker.from_pretrained()
el_checker.from_pretrained()
cl_checker.from_pretrained()
print("Dummy run", bl_checker.correct("I luk foward to receving your reply"))
print("Dummy run", el_checker.correct("I luk foward to receving your reply"))
print("Dummy run", cl_checker.correct("I luk foward to receving your reply"))

import uvicorn
from fastapi import File
from fastapi import FastAPI
import sys

app = FastAPI()
print("Models loaded !")


@app.get("/")
def read_root():
    return {"Neuspell !"}

@app.get("/{correct}")
def get_correction(input_sentence, model):
    '''Returns spell corrected sentence using the model passed in model param.'''
    if model == "BERT-LSTM":
        return {"corrected_sentence": bl_checker.correct(input_sentence)}
    elif model == "ELMo-LSTM":  
        return {"corrected_sentence": el_checker.correct(input_sentence)}
    else:
        return {"corrected_sentence": cl_checker.correct(input_sentence)}