Exemplo n.º 1
0
def home():
    if request.method == "POST":
        sentence = str(request.form.get("twt"))

        sentiment = predict_sentiment(sentence, classifier)

        # adding emoji to the sentiment
        if sentiment == "Positive":
            sentiment += " \U0001f600"

        elif sentiment == "Negative":
            sentiment += " \U0001F641"

        else:
            pass

        # creating an instance of the data table for the database and commiting the changes
        usr_data = New_Data(sentence, sentiment.split()[0])
        try:
            db.session.add(usr_data)
            db.session.commit()
        except:
            pass

        text = 'You have entered "' + sentence + '"'
        return render_template("index.html",
                               text=text,
                               sentiment="Sentiment: " + sentiment)

    return render_template("index.html")
Exemplo n.º 2
0
def home():
    if request.method == 'POST':
        sentence = request.form.get('twt')

        sentiment = predict_sentiment(sentence, classifier)

        # adding emoji to the sentiment
        if sentiment == "Positive":
            sentiment += " \U0001f600"

        elif sentiment == "Negative":
            sentiment += " \U0001F641"

        else:
            pass

        # creating an instance of the data table for the database and commiting the changes
        usr_data = New_Data(sentence, sentiment.split()[0])
        db.session.add(usr_data)
        db.session.commit()

        text = "You have entered \"" + sentence + "\""
        return render_template('index.html',
                               text=text,
                               sentiment="Sentiment: " + sentiment)

    return render_template('index.html')
Exemplo n.º 3
0
def fast_api(sentence):
    sentiment = predict_sentiment(sentence, classifier)

    return jsonify({"sentence": sentence, "sentiment": sentiment})
Exemplo n.º 4
0
def fast_api(sentence):
    sentiment = predict_sentiment(sentence, classifier)

    return jsonify({'sentence': sentence, 'sentiment': sentiment})