Spaces:
Sleeping
Sleeping
File size: 667 Bytes
d08668b |
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 |
# ======= 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) |