INNER CODE UNIT · Python

make_prediction

NirantK/NLP_Quickbook · Part-08 Web Deployments/api.py:42

def make_prediction():
    if request.method == "POST":
        # get uploaded file if it exists
        logger.debug(request.files)

        f = request.files["file"]
        f.save(f.filename)  # save file to disk
        logger.info(f"{f.filename} saved to disk")

        # read file from disk
        with open(f.filename, "r") as infile:
            text_content = infile.read()
        logger.info(f"Text Content from file read")

        prediction = model.predict([text_content])
        logger.info(f"prediction: {prediction}")
        prediction = "pos" if prediction[0] == 1 else "neg"
        os.remove(f.filename)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…