예제 #1
0
파일: app.py 프로젝트: zoosky/loki
def post_emotion():
    data = request.get_json(silent=True)

    if data.get('emotion'):
        Emotion.create(data=data)
        print("{}: Recorded {} datapoint.".format(datetime.datetime.now(), data['emotion']))
        return jsonify(data)

    else:
        return jsonify({'error': 'invalid data'})
예제 #2
0
def test_create_emotion():
    str = '''{
            "anger": 0.037,
            "contempt": 0.001,
            "disgust": 0.015,
            "fear": 0.001,
            "happiness": 0.939,
            "neutral": 0.001,
            "sadness": 0.0,
            "surprise": 0.007
          }'''

    u = User(username='******', password='******')
    e = Emotion(user=u,
                emotion_json=str,
                res='',
                date=datetime.now().strftime("%Y-%m-%d %H:%M"))

    parsed = json.loads(str)
    assert parsed['anger'] == e.anger
    assert parsed['contempt'] == e.contempt
    assert parsed['disgust'] == e.disgust
    assert parsed['fear'] == e.fear
    assert parsed['happiness'] == e.happiness
    assert parsed['neutral'] == e.neutral
    assert parsed['sadness'] == e.sadness
    assert parsed['surprise'] == e.surprise

    assert datetime.now().strftime("%Y-%m-%d %H:%M") == e.date
예제 #3
0
def test_user_create_emotion():
    u = User(username='******', password='******')
    u.id = 1
    str = '''{
        "anger": 0.037,
        "contempt": 0.001,
        "disgust": 0.015,
        "fear": 0.001,
        "happiness": 0.939,
        "neutral": 0.001,
        "sadness": 0.0,
        "surprise": 0.007
      }'''

    e = Emotion(user=u, emotion_json=str, res='', date=datetime.now())
    u.append_emotion(e)
    assert u.emotions[0] == e
예제 #4
0
def make_return_data(api_result, user):
    return_data = dict()
    if len(api_result) > 0:
        user_emotion = str(
            json.dumps(api_result[0]["faceAttributes"]["emotion"]))
        represent_emotion = analysis_emotion_process(
            api_result[0]["faceAttributes"])

        ment = ReplyMent.query.filter_by(emotion=represent_emotion).first()
        e = Emotion(user=user,
                    emotion_json=user_emotion,
                    res=represent_emotion)
        db.session.add(e)
        db.session.commit()

        return_data["code"] = 200
        return_data = json.loads(user_emotion)
        return_data["represent_emotion"] = represent_emotion
        return_data["represent_age"] = api_result[0]["faceAttributes"]["age"]
        return_data["represent_gender"] = api_result[0]["faceAttributes"][
            "gender"]
        return_data["ment"] = ment.reply_ment
        return_data["tts"] = ment.tts
        if ment.tag2 is None:
            return_data[
                "bgm"] = 'https://s3.ap-northeast-2.amazonaws.com/ryun.capstone/sadness.mp3'
        else:
            return_data["bgm"] = ment.tag2

    elif len(api_result) == 0:
        return_data["code"] = 203
        return_data["msg"] = "No Match Face"

    else:
        return_data["code"] = 404
        return_data["msg"] = "Other Error!"
    return return_data
예제 #5
0
파일: ajax.py 프로젝트: eecrazy/Emotion
def lookuporinsert_emo(emotion):
	emotion = emotion.strip()
	emo_object = None
	if emotion:
		try:
			emo_object = Emotion.objects.get(emo_content=emotion)
		except Emotion.DoesNotExist:
			emo_object = None
		if not emo_object:
			#create emo object
			emo_object = Emotion()

			emo_object.emo_content = emotion
			emo_object.emo_upload_user = get_user_by_id(ANOYMOUS)
			emo_object.emo_type = EMO_TEXT

			emo_object.save()
		return emo_object
	return None
예제 #6
0
파일: classifier.py 프로젝트: zoosky/loki
 def loadDBData(self):
     db_data = []
     for entry in Emotion.select():
         db_data.append(entry.data)
     return db_data
예제 #7
0
파일: app.py 프로젝트: zoosky/loki
def get_data():
    return jsonify([e.data for e in Emotion.select()])
예제 #8
0
파일: app.py 프로젝트: zoosky/loki
    hist = train_model(output_mlmodel=True)
    return jsonify(hist)


@app.route('/model')
def serve_model():
    # if not os.path.isfile('model.mlmodel'):
    print("Training model to serve...")
    train_model_endpoint()

    return send_file(
        filename_or_fp='model.mlmodel',
        mimetype='application/octet-stream',
        as_attachment=True,
        attachment_filename='EmotionModel.mlmodel',
    )


@app.route('/data')
def get_data():
    return jsonify([e.data for e in Emotion.select()])


if __name__ == '__main__':
    db.connect()
    Emotion.create_table(fail_silently=True)
    db.close()

    port = int(os.environ.get('PORT', 5001))
    app.run(host='0.0.0.0', port=port)