Created
December 16, 2019 20:20
-
-
Save aballah-chamakh/5962a2830ed244e94958dd49b18a76d1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from MyApp.celery import app | |
from .models import SentimentAnalysisInference | |
import nltk.sentiment.vader import SentimentIntensityAnalyzer | |
@app.task(bind=True) | |
def run_inference(self, sa_id): | |
sai_inference_obj = SentimentAnalysisInference.objects.get(id=sa_id) | |
sid = SentimentIntensityAnalyzer() | |
compound = sid.polarity_scores(sai_inference.text)['compountd'] | |
if compound > 0.5 : | |
sai_inference_obj.result = 'Happy' | |
elif compound < 0.5 : | |
sai_inference_obj.result = 'Happy' | |
else : | |
sai_inference_obj.result = 'neutral' | |
sai_inference_obj.save() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment