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)}