Created
December 16, 2019 20:25
-
-
Save aballah-chamakh/6e92cfb80400eb68336c6bd26a0897d5 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 rest_framework import serializers | |
from .models import SentimentAnalysisInference | |
import nltk.sentiment.vader import SentimentIntensityAnalyzer | |
from .tasks import run_inference | |
class SentimentAnalysisInferenceSerializer(serializers.ModelSerializer): | |
username = serializers.CharField(source='user.username',read_only=True) | |
class Meta : | |
model = SentimentAnalysisInference | |
fields = ['username','text','result'] | |
def create(self.,validated_data): | |
text = validated_data['text'] | |
user_obj = self.request.user | |
sai_inference_obj = SentimentAnalysisInference.objects.create(user=user_obj) | |
run_infernece.delay(sai_inference_obj.id) | |
return sai_inference_obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment