Created
June 25, 2021 08:06
-
-
Save Davisy/798e4d0f51664bd326548627e89502b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.get("/predict-review") | |
def predict_sentiment(review: str): | |
""" | |
A simple function that receive a review content and predict the sentiment of the content. | |
:param review: | |
:return: prediction, probabilities | |
""" | |
# clean the review | |
cleaned_review = text_cleaning(review) | |
# perform prediction | |
prediction = model.predict([cleaned_review]) | |
output = int(prediction[0]) | |
probas = model.predict_proba([cleaned_review]) | |
output_probability = "{:.2f}".format(float(probas[:, output])) | |
# output dictionary | |
sentiments = {0: "Negative", 1: "Positive"} | |
# show results | |
result = {"prediction": sentiments[output], "Probability": output_probability} | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment