def recognitions(): if request.method == 'POST': data = request.get_json() x = data["base64Image"].split(',') base64_decoded = base64.b64decode(x[1]) image = Image.open(io.BytesIO(base64_decoded)) image_np = np.array(image) t = time.time() result = get_emotion(image_np) print(result) print(time.time() - t) return json.dumps(result)
def post(self, id): args = self.reqparse.parse_args() text = args["text"] # getting sentiment analysis from google nlp api annotations = get_sentiment(text) sentiment = annotations.document_sentiment.score # getting emotion from deepaffects text api emotion = list(json.loads(get_emotion(text).text)["response"].keys())[0] ketchup = CheckIn(id, text, sentiment, emotion) self.add_checkin_to_db(ketchup) most_common, average, slope, r2 = self.get_data(id) return jsonify({"emotion": emotion, "sentiment": sentiment, "most_freq_emotion": most_common, "average_sentiment": average, "slope": slope, "r2": r2})
def predict(): label = get_emotion() return redirect('/musicplayer?mood=' + label)
import pandas as pd import re #清楚数字标点的标准库 from textblob import TextBlob import emotion from nltk.corpus import stopwords # 下载之后 载入字典 from nltk.stem.porter import PorterStemmer # stem:词根 PorterStemmer: 词根函数库 positive, negative = emotion.get_emotion() positive = tuple(positive) negative = tuple(negative) table = "microwave" # dataset = pd.read_csv('data/hair_dryer.tsv', delimiter = '\t', quoting = 3, encoding='utf-8') # dataset = pd.read_csv('data/pacifier.tsv', delimiter = '\t', quoting = 3, encoding='utf-8') dataset = pd.read_csv('data/microwave.tsv', delimiter = '\t', quoting = 3, encoding='utf-8') def get_scores(): corpus = [] # 空list lens = len(dataset) listc = [] mp = dict() k = 0 sum = 0 scorce = [] sum_count = 0 for i in range(0, lens):
def get_emotion_of_text(): if request.method == 'POST': text = request.json.get('text') return get_emotion(text)