Added coffeehouse_emotions
This commit is contained in:
parent
3c494acd87
commit
9e785c73ec
|
@ -23,6 +23,8 @@ echo "### Starting CoffeeHouse-CoreNLP ###"
|
|||
make start_corenlp &
|
||||
echo "### Starting CoffeeHouse-NSFW ###"
|
||||
make start_nsfw &
|
||||
echo "### Starting CoffeeHouse-Emotions ###"
|
||||
make start_emotions &
|
||||
|
||||
echo "### Checking Service Status ###"
|
||||
|
||||
|
@ -60,6 +62,13 @@ while sleep 60; do
|
|||
exit 1
|
||||
fi
|
||||
|
||||
ps aux | grep coffeehouse_emotions | grep -q -v grep
|
||||
EMOTION_STATUS=$?
|
||||
if [ $EMOTION_STATUS -ne 0 ]; then
|
||||
echo "ERROR: coffeehouse_emotion has been terminated, terminating container."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ps aux | grep coffeehouse_ping | grep -q -v grep
|
||||
PING_STATUS=$?
|
||||
if [ $PING_STATUS -ne 0 ]; then
|
||||
|
|
15
Makefile
15
Makefile
|
@ -28,6 +28,9 @@ clean_langdetect:
|
|||
clean_spamdetect:
|
||||
rm -rf services/spam_detection/build services/spam_detection/dist services/spam_detection/coffeehouse_spamdetection.egg-info
|
||||
|
||||
clean_emotions:
|
||||
rm -rf services/emotions/build services/emotions/dist services/emotions/coffeehouse_emotions.egg-info
|
||||
|
||||
clean_ping:
|
||||
rm -rf services/ping_service/build services/ping_service/dist services/ping_service/coffeehouse_ping.egg-info
|
||||
|
||||
|
@ -49,6 +52,7 @@ clean:
|
|||
make clean_translation
|
||||
make clean_langdetect
|
||||
make clean_spamdetect
|
||||
make clean_emotions
|
||||
make clean_nsfw
|
||||
make clean_corenlp
|
||||
make clean_ping
|
||||
|
@ -89,6 +93,9 @@ build_langdetect:
|
|||
build_spamdetect:
|
||||
cd services/spam_detection; python3 setup.py build; python3 setup.py sdist
|
||||
|
||||
build_emotions:
|
||||
cd services/emotions; python3 setup.py build; python3 setup.py sdist
|
||||
|
||||
build_translation:
|
||||
cd services/translation; python3 setup.py build; python3 setup.py sdist
|
||||
|
||||
|
@ -110,6 +117,7 @@ build:
|
|||
make buid_translation
|
||||
make build_langdetect
|
||||
make build_spamdetect
|
||||
make build_emotions
|
||||
make build_nsfw
|
||||
make build_corenlp
|
||||
make build_ping
|
||||
|
@ -151,6 +159,9 @@ install_langdetect:
|
|||
install_spamdetect:
|
||||
cd services/spam_detection; python3 setup.py install
|
||||
|
||||
install_emotions:
|
||||
cd services/emotions; python3 setup.py install
|
||||
|
||||
install_translation:
|
||||
cd services/translation; python3 setup.py install
|
||||
|
||||
|
@ -175,6 +186,7 @@ install:
|
|||
make install_translation
|
||||
make install_langdetect
|
||||
make install_spamdetect
|
||||
make install_emotions
|
||||
make install_nsfw
|
||||
make build_corenlp
|
||||
make install_ping
|
||||
|
@ -205,6 +217,9 @@ start_langdetect:
|
|||
start_spamdetect:
|
||||
python3 -m coffeehouse_spamdetection --start-server
|
||||
|
||||
start_emotions:
|
||||
python3 -m coffeehouse_emotions --start-server
|
||||
|
||||
start_translation:
|
||||
python3 -m coffeehouse_translation --start-server
|
||||
|
||||
|
|
|
@ -44,4 +44,5 @@ make start_translate # Starts the translation server, runs on port 5603
|
|||
| CoffeeHouse NSFW Classifier | HTTP | 5602 |
|
||||
| CoffeeHouse Translate | HTTP | 5603 |
|
||||
| CoffeeHouse CoreNLP | HTTP | 5604 |
|
||||
| CoffeeHouse Emotions | HTTP | 5605 |
|
||||
| CoffeeHouse Language Detection | HTTP | 5606 |
|
|
@ -0,0 +1,3 @@
|
|||
# CoffeeHouse Emotion
|
||||
|
||||
Library for detecting emotions :)
|
|
@ -0,0 +1,7 @@
|
|||
from . import main
|
||||
from .main import *
|
||||
|
||||
from . import server
|
||||
from .server import *
|
||||
|
||||
__all__ = ["main", "SpamDetection", "Server"]
|
|
@ -0,0 +1,70 @@
|
|||
import sys
|
||||
|
||||
from .main import EmotionPrediction
|
||||
from .server import Server
|
||||
|
||||
|
||||
def _real_main(argv=None):
|
||||
"""
|
||||
The main command-line processor
|
||||
|
||||
:param argv:
|
||||
:return:
|
||||
"""
|
||||
if argv[1] == '--help':
|
||||
_help_menu(argv)
|
||||
if argv[1] == '--test':
|
||||
_test_model(argv)
|
||||
if argv[1] == '--start-server':
|
||||
_start_server(argv)
|
||||
|
||||
|
||||
def _start_server(argv=None):
|
||||
"""
|
||||
Starts the server
|
||||
|
||||
:param argv:
|
||||
:return:
|
||||
"""
|
||||
server = Server()
|
||||
server.start()
|
||||
|
||||
|
||||
def _help_menu(argv=None):
|
||||
"""
|
||||
Displays the help menu and commandline usage
|
||||
|
||||
:param argv:
|
||||
:return:
|
||||
"""
|
||||
print(
|
||||
"CoffeeHouse EmotionPrediction CLI\n\n"
|
||||
" --help\n"
|
||||
" --test\n"
|
||||
" --start-server\n"
|
||||
)
|
||||
sys.exit()
|
||||
|
||||
|
||||
def _test_model(argv=None):
|
||||
"""
|
||||
Tests the model's prediction by allowing user input and displaying the
|
||||
prediction output
|
||||
|
||||
:param argv:
|
||||
:return:
|
||||
"""
|
||||
print("Loading")
|
||||
emotion_prediction = EmotionPrediction()
|
||||
print("Ready\n")
|
||||
|
||||
while True:
|
||||
input_text = input("> ")
|
||||
print(emotion_prediction.predict(input_text))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
_real_main(sys.argv)
|
||||
except KeyboardInterrupt:
|
||||
print('\nInterrupted by user')
|
|
@ -0,0 +1,30 @@
|
|||
import os
|
||||
from resource_fetch import ResourceFetch
|
||||
from coffeehouse_dltc.main import DLTC
|
||||
|
||||
__all__ = ['EmotionPrediction']
|
||||
|
||||
|
||||
class EmotionPrediction(object):
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Public Constructor
|
||||
"""
|
||||
self.dltc = DLTC()
|
||||
self.rf = ResourceFetch()
|
||||
self.model_directory = os.path.join(
|
||||
self.rf.fetch("Intellivoid", "CoffeeHouseData-ProfleIO"),
|
||||
"advanced_sentiments_build"
|
||||
)
|
||||
self.dltc.load_model_cluster(self.model_directory)
|
||||
|
||||
def predict(self, text_input):
|
||||
"""
|
||||
Takes the user input and predicts if the input is either
|
||||
spam or ham
|
||||
|
||||
:param text_input:
|
||||
:return: Returns dictionary "neutral", "happiness", "affection", "sadness" and "anger" prediction values
|
||||
"""
|
||||
return self.dltc.predict_from_text(text_input)
|
|
@ -0,0 +1,58 @@
|
|||
from hyper_internal_service import web
|
||||
|
||||
from .main import EmotionPrediction
|
||||
|
||||
__all__ = ['Server']
|
||||
|
||||
|
||||
class Server(object):
|
||||
|
||||
def __init__(self, port=5605):
|
||||
"""
|
||||
Public Constructor
|
||||
:param port:
|
||||
"""
|
||||
self.port = port
|
||||
self.web_application = web.Application()
|
||||
self.web_application.add_routes(
|
||||
[web.post('/', self.predict)]
|
||||
)
|
||||
self.emotion_prediction = EmotionPrediction()
|
||||
|
||||
async def predict(self, request):
|
||||
"""
|
||||
Handles the predict request "/", usage:
|
||||
POST:: "input": str
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
post_data = await request.post()
|
||||
results = self.emotion_prediction.predict(post_data['input'])
|
||||
response = {
|
||||
"status": True,
|
||||
"results": {
|
||||
"neutral": str(results['neutral']),
|
||||
"happiness": str(results['happiness']),
|
||||
"affection": str(results['affection']),
|
||||
"sadness": str(results['sadness']),
|
||||
"anger": str(results['anger'])
|
||||
}
|
||||
}
|
||||
return web.json_response(response)
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Starts the web application
|
||||
:return:
|
||||
"""
|
||||
web.run_app(app=self.web_application, port=self.port)
|
||||
return True
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stops the web application
|
||||
:return:
|
||||
"""
|
||||
self.web_application.shutdown()
|
||||
self.web_application.cleanup()
|
||||
return True
|
|
@ -0,0 +1,31 @@
|
|||
from setuptools import setup, find_packages
|
||||
from setuptools.command.install import install
|
||||
|
||||
|
||||
class PostInstallCommand(install):
|
||||
"""Post-installation for installation mode."""
|
||||
|
||||
def run(self):
|
||||
install.run(self)
|
||||
from resource_fetch import ResourceFetch
|
||||
rf = ResourceFetch()
|
||||
|
||||
# Update the model
|
||||
rf.fetch("Intellivoid", "CoffeeHouseData-ProfileIO")
|
||||
setup(
|
||||
name='coffeehouse_emotions',
|
||||
version='1.0.0',
|
||||
description='Predicts input to probable emotions',
|
||||
url='https://github.com/Intellivoid/CoffeeHousePy',
|
||||
author='Zi Xing Narrakas',
|
||||
author_email='netkas@intellivoid.info',
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Internal/Alpha',
|
||||
'Topic :: Text Processing',
|
||||
'Programming Language :: Python :: 3',
|
||||
],
|
||||
cmdclass={
|
||||
'install': PostInstallCommand,
|
||||
},
|
||||
packages=find_packages()
|
||||
)
|
Loading…
Reference in New Issue