def predict_sentiment(): if request.method == 'POST': a = time.monotonic() # Form being submitted; grab data from form. text = request.args.get('text', '') sentiment = make_predictions(text) sentiment = sentiment[0] b = time.monotonic() c = b - a # For saving to database new_prediction = PredictionsModel(input_text=text, prediction=sentiment, time=c) db.session.add(new_prediction) db.session.commit() # Database task finished response = { 'text': text, 'sentiment': sentiment, 'messsage': "New entry saved to database" } response = jsonify(response) return response
def predict_sentiment(): if request.method == 'POST': # Form being submitted; grab data from form. text = request.args.get("text", '') a = time.monotonic() print("printing the text {}".format( request.get_json(force=True)['text'])) text = request.get_json(force=True)['text'] sentiment, probability = make_predictions(text) sentiment = sentiment[0] b = time.monotonic() time_elapsed = b - a response = { 'sentiment': sentiment, 'eta': time_elapsed, 'confidence': probability } response = jsonify(response) database_item = { 'query': text, 'sentiment': sentiment, 'eta': time_elapsed, 'confidence': probability } # inserting to dtabase #client = MongoClient(MONGO_URL) client = MongoClient(os.environ['DB_PORT_27017_TCP_ADDR'], 27017) db = client['sentiments'] sentiments = db.sentiments sentiments.insert_one(database_item) return response
def find_sentiment(): if request.method == 'POST': # Form being submitted; grab data from form. text = request.form['text'] a = time.monotonic() sentiment, probability = make_predictions(text) sentiment = sentiment[0] b = time.monotonic() time_elapsed = b - a database_item = { 'query': text, 'sentiment': sentiment, 'eta': time_elapsed, 'confidence': probability } # inserting to dtabase #client = MongoClient(MONGO_URL) client = MongoClient(os.environ['DB_PORT_27017_TCP_ADDR'], 27017) db = client['sentiments'] sentiments = db.sentiments sentiments.insert_one(database_item) return render_template('submit_text.html', message=sentiment) return render_template('submit_text.html')
def find_sentiment(): if request.method == 'POST': # Form being submitted; grab data from form. text = request.form['text'] print(text) sentiment = make_predictions(text) print(sentiment) return render_template('submit_text.html', message=sentiment[0]) return render_template('submit_text.html')
from __future__ import absolute_import import os import sys import argparse print(os.path.realpath(__file__)) full_absolute_location = os.path.realpath(__file__) full_absolute_location = full_absolute_location.split("/") full_absolute_location = "/".join( full_absolute_location[:-2]) sys.path.append(os.path.join(full_absolute_location, 'src')) from models.predict_model import make_predictions sentiment = make_predictions("I am very very happy") print(sentiment)