Skip to content

Instantly share code, notes, and snippets.

@aballah-chamakh
Created December 16, 2019 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aballah-chamakh/5962a2830ed244e94958dd49b18a76d1 to your computer and use it in GitHub Desktop.
Save aballah-chamakh/5962a2830ed244e94958dd49b18a76d1 to your computer and use it in GitHub Desktop.
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