Added coffeehouse_emotions

This commit is contained in:
Netkas 2021-01-15 18:35:14 -05:00
parent 3c494acd87
commit 9e785c73ec
9 changed files with 458 additions and 234 deletions

View File

@ -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

483
Makefile
View File

@ -1,235 +1,250 @@
clean_apt:
rm -rf mods/apt/build mods/apt/dist mods/apt/coffeehousemod_apt.egg-info
clean_stopwords:
rm -rf mods/stopwords/build mods/stopwords/dist mods/stopwords/coffeehousemod_stopwords.egg-info
clean_tokenizer:
rm -rf mods/tokenizer/build mods/tokenizer/dist mods/tokenizer/coffeehousemod_tokenizer.egg-info
clean_dltc:
rm -rf dltc/build dltc/dist dltc/coffeehouse_dltc.egg-info
clean_nlpfr:
rm -rf nlpfr/build nlpfr/dist nlpfr/nltk.egg-info
clean_alg:
rm -rf alg/build alg/dist alg/coffeehouse_alg.egg-info
clean_rf:
rm -rf resource_fetch/build resource_fetch/dist resource_fetch/resource_fetch.egg-info
clean_his:
rm -rf hyper_internal_service/build hyper_internal_service/dist hyper_internal_service/hyper_internal_service.egg-info
clean_langdetect:
rm -rf services/language_detection/build services/language_detection/dist services/language_detection/coffeehouse_languagedetection.egg-info
clean_spamdetect:
rm -rf services/spam_detection/build services/spam_detection/dist services/spam_detection/coffeehouse_spamdetection.egg-info
clean_ping:
rm -rf services/ping_service/build services/ping_service/dist services/ping_service/coffeehouse_ping.egg-info
clean_translation:
rm -rf services/translation/build services/translation/dist services/translation/coffeehouse_translation.egg-info
clean_corenlp:
cd services/corenlp; make clean
clean_nsfw:
rm -rf services/nsfw_detection/build services/nsfw_detection/dist services/nsfw_detection/coffeehouse_nsfw.egg-info
clean:
make clean_apt clean_stopwords clean_tokenizer clean_nlpfr
make clean_dltc
make clean_his
make clean_alg
make clean_rf
make clean_translation
make clean_langdetect
make clean_spamdetect
make clean_nsfw
make clean_corenlp
make clean_ping
# ======================================================================================================================
build_apt:
cd mods/apt; python3 setup.py build; python3 setup.py sdist
build_stopwords:
cd mods/stopwords; python3 setup.py build; python3 setup.py sdist
build_tokenizer:
cd mods/tokenizer; python3 setup.py build; python3 setup.py sdist
build_mods:
make build_apt build_stopwords build_tokenizer
build_nlpfr:
make build_mods
cd nlpfr; python3 setup.py build; python3 setup.py sdist
build_dltc:
cd dltc; python3 setup.py build; python3 setup.py sdist
build_alg:
cd alg; python3 setup.py build; python3 setup.py sdist
build_his:
cd hyper_internal_service; python3 setup.py build; python3 setup.py sdist
build_rf:
cd resource_fetch; python3 setup.py build; python3 setup.py sdist
build_langdetect:
cd services/language_detection; python3 setup.py build; python3 setup.py sdist
build_spamdetect:
cd services/spam_detection; python3 setup.py build; python3 setup.py sdist
build_translation:
cd services/translation; python3 setup.py build; python3 setup.py sdist
build_corenlp:
cd services/corenlp; make build
build_nsfw:
cd services/nsfw_detection; python3 setup.py build; python3 setup.py sdist
build_ping:
cd services/ping_service; python3 setup.py build; python3 setup.py sdist
build:
make build_nlpfr
make build_his
make build_dltc
make build_alg
make build_rf
make buid_translation
make build_langdetect
make build_spamdetect
make build_nsfw
make build_corenlp
make build_ping
# ======================================================================================================================
install_apt:
cd mods/apt; python3 setup.py install
install_stopwords:
cd mods/stopwords; python3 setup.py install
install_tokenizer:
cd mods/tokenizer; python3 setup.py install
install_mods:
make install_apt install_stopwords install_tokenizer
install_nlpfr:
make install_mods
cd nlpfr; python3 setup.py install
install_dltc:
cd dltc; python3 setup.py install
install_alg:
cd alg; python3 setup.py install
install_his:
cd hyper_internal_service; python3 -m pip install -Ur dev_requirements.txt; python3 setup.py install
install_rf:
cd resource_fetch; python3 setup.py install
python3 -m resource_fetch
install_langdetect:
cd services/language_detection; python3 setup.py install
install_spamdetect:
cd services/spam_detection; python3 setup.py install
install_translation:
cd services/translation; python3 setup.py install
install_nsfw:
python3 -m pip install opencv-python
python3 -m pip install scikit-image
python3 -m pip install pydload
cd services/nsfw_detection; python3 setup.py install
install_ping:
cd services/ping_service; python3 setup.py install
install_full:
make install_rf
make install
install:
make install_nlpfr
make install_his
make install_dltc
make install_alg
make install_translation
make install_langdetect
make install_spamdetect
make install_nsfw
make build_corenlp
make install_ping
# ======================================================================================================================
system_prep_python:
apt -y install python3 python3-distutils python3-dev python3-setuptools
system_prep_pip:
apt -y install wget curl
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
rm get-pip.py
system_prep_gcc:
apt -y install gcc build-essential
python3 -m pip install cython
system_prep_java:
apt -y install openjdk-8-jre openjdk-8-jdk ant
# ======================================================================================================================
start_langdetect:
python3 -m coffeehouse_languagedetection --start-server
start_spamdetect:
python3 -m coffeehouse_spamdetection --start-server
start_translation:
python3 -m coffeehouse_translation --start-server
start_nsfw:
python3 -m coffeehouse_nsfw --start-server
start_corenlp:
cd services/corenlp; make start
start_ping:
python3 -m coffeehouse_ping --start-server
start_warmup:
cd scripts; python3 warmup.py
# ======================================================================================================================
docker_build:
docker build -t="coffeehouse_utils" -f Dockerfile .
docker_run:
docker run -it --name coffeehouse_utils -h coffeehouse_utils --restart always -p 5600:5600 -p 5601:5601 -p 5602:5602 -p 5603:5603 -p 5604:5604 -p 5606:5606 coffeehouse_utils
docker_run_no_expose:
docker run -it --name coffeehouse_utils -h coffeehouse_utils --restart always coffeehouse_utils
docker_rm:
clean_apt:
rm -rf mods/apt/build mods/apt/dist mods/apt/coffeehousemod_apt.egg-info
clean_stopwords:
rm -rf mods/stopwords/build mods/stopwords/dist mods/stopwords/coffeehousemod_stopwords.egg-info
clean_tokenizer:
rm -rf mods/tokenizer/build mods/tokenizer/dist mods/tokenizer/coffeehousemod_tokenizer.egg-info
clean_dltc:
rm -rf dltc/build dltc/dist dltc/coffeehouse_dltc.egg-info
clean_nlpfr:
rm -rf nlpfr/build nlpfr/dist nlpfr/nltk.egg-info
clean_alg:
rm -rf alg/build alg/dist alg/coffeehouse_alg.egg-info
clean_rf:
rm -rf resource_fetch/build resource_fetch/dist resource_fetch/resource_fetch.egg-info
clean_his:
rm -rf hyper_internal_service/build hyper_internal_service/dist hyper_internal_service/hyper_internal_service.egg-info
clean_langdetect:
rm -rf services/language_detection/build services/language_detection/dist services/language_detection/coffeehouse_languagedetection.egg-info
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
clean_translation:
rm -rf services/translation/build services/translation/dist services/translation/coffeehouse_translation.egg-info
clean_corenlp:
cd services/corenlp; make clean
clean_nsfw:
rm -rf services/nsfw_detection/build services/nsfw_detection/dist services/nsfw_detection/coffeehouse_nsfw.egg-info
clean:
make clean_apt clean_stopwords clean_tokenizer clean_nlpfr
make clean_dltc
make clean_his
make clean_alg
make clean_rf
make clean_translation
make clean_langdetect
make clean_spamdetect
make clean_emotions
make clean_nsfw
make clean_corenlp
make clean_ping
# ======================================================================================================================
build_apt:
cd mods/apt; python3 setup.py build; python3 setup.py sdist
build_stopwords:
cd mods/stopwords; python3 setup.py build; python3 setup.py sdist
build_tokenizer:
cd mods/tokenizer; python3 setup.py build; python3 setup.py sdist
build_mods:
make build_apt build_stopwords build_tokenizer
build_nlpfr:
make build_mods
cd nlpfr; python3 setup.py build; python3 setup.py sdist
build_dltc:
cd dltc; python3 setup.py build; python3 setup.py sdist
build_alg:
cd alg; python3 setup.py build; python3 setup.py sdist
build_his:
cd hyper_internal_service; python3 setup.py build; python3 setup.py sdist
build_rf:
cd resource_fetch; python3 setup.py build; python3 setup.py sdist
build_langdetect:
cd services/language_detection; python3 setup.py build; python3 setup.py sdist
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
build_corenlp:
cd services/corenlp; make build
build_nsfw:
cd services/nsfw_detection; python3 setup.py build; python3 setup.py sdist
build_ping:
cd services/ping_service; python3 setup.py build; python3 setup.py sdist
build:
make build_nlpfr
make build_his
make build_dltc
make build_alg
make build_rf
make buid_translation
make build_langdetect
make build_spamdetect
make build_emotions
make build_nsfw
make build_corenlp
make build_ping
# ======================================================================================================================
install_apt:
cd mods/apt; python3 setup.py install
install_stopwords:
cd mods/stopwords; python3 setup.py install
install_tokenizer:
cd mods/tokenizer; python3 setup.py install
install_mods:
make install_apt install_stopwords install_tokenizer
install_nlpfr:
make install_mods
cd nlpfr; python3 setup.py install
install_dltc:
cd dltc; python3 setup.py install
install_alg:
cd alg; python3 setup.py install
install_his:
cd hyper_internal_service; python3 -m pip install -Ur dev_requirements.txt; python3 setup.py install
install_rf:
cd resource_fetch; python3 setup.py install
python3 -m resource_fetch
install_langdetect:
cd services/language_detection; python3 setup.py install
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
install_nsfw:
python3 -m pip install opencv-python
python3 -m pip install scikit-image
python3 -m pip install pydload
cd services/nsfw_detection; python3 setup.py install
install_ping:
cd services/ping_service; python3 setup.py install
install_full:
make install_rf
make install
install:
make install_nlpfr
make install_his
make install_dltc
make install_alg
make install_translation
make install_langdetect
make install_spamdetect
make install_emotions
make install_nsfw
make build_corenlp
make install_ping
# ======================================================================================================================
system_prep_python:
apt -y install python3 python3-distutils python3-dev python3-setuptools
system_prep_pip:
apt -y install wget curl
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
rm get-pip.py
system_prep_gcc:
apt -y install gcc build-essential
python3 -m pip install cython
system_prep_java:
apt -y install openjdk-8-jre openjdk-8-jdk ant
# ======================================================================================================================
start_langdetect:
python3 -m coffeehouse_languagedetection --start-server
start_spamdetect:
python3 -m coffeehouse_spamdetection --start-server
start_emotions:
python3 -m coffeehouse_emotions --start-server
start_translation:
python3 -m coffeehouse_translation --start-server
start_nsfw:
python3 -m coffeehouse_nsfw --start-server
start_corenlp:
cd services/corenlp; make start
start_ping:
python3 -m coffeehouse_ping --start-server
start_warmup:
cd scripts; python3 warmup.py
# ======================================================================================================================
docker_build:
docker build -t="coffeehouse_utils" -f Dockerfile .
docker_run:
docker run -it --name coffeehouse_utils -h coffeehouse_utils --restart always -p 5600:5600 -p 5601:5601 -p 5602:5602 -p 5603:5603 -p 5604:5604 -p 5606:5606 coffeehouse_utils
docker_run_no_expose:
docker run -it --name coffeehouse_utils -h coffeehouse_utils --restart always coffeehouse_utils
docker_rm:
docker rm -f coffeehouse_utils

View File

@ -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 |

View File

@ -0,0 +1,3 @@
# CoffeeHouse Emotion
Library for detecting emotions :)

View File

@ -0,0 +1,7 @@
from . import main
from .main import *
from . import server
from .server import *
__all__ = ["main", "SpamDetection", "Server"]

View File

@ -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')

View File

@ -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)

View File

@ -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

View File

@ -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()
)