geetu040's picture
Initial Upload
d08668b
# ======= PREPARING THE PIPELINE =======
import torch
import os
from utils.preprocess import get_preprocess
from utils.model import get_model
dump_path = "./dumps/"
vocab_path = os.path.join(dump_path, "vocab.pt")
model_path = os.path.join(dump_path, "model.pt")
params_path = os.path.join(dump_path, "params.json")
preprocess = get_preprocess(vocab_path)
model = get_model(model_path, params_path)
def predict(text):
x = preprocess(text)
x = torch.tensor([x])
y = model(x)
y = y.detach().numpy().tolist()[0]
return y
# ======= CREATING APP =======
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def main(text: str):
return predict(text)