mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 12:06:37 +00:00
New function
This commit is contained in:
17
sample-functions/SentimentAnalysis/Dockerfile
Normal file
17
sample-functions/SentimentAnalysis/Dockerfile
Normal file
@ -0,0 +1,17 @@
|
||||
FROM python:2.7-alpine
|
||||
RUN pip install textblob
|
||||
RUN python -m textblob.download_corpora
|
||||
|
||||
ADD https://github.com/alexellis/faas/releases/download/0.5.1-alpha/fwatchdog /usr/bin
|
||||
RUN chmod +x /usr/bin/fwatchdog
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
COPY handler.py .
|
||||
|
||||
ENV fprocess="python handler.py"
|
||||
|
||||
HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1
|
||||
|
||||
CMD ["fwatchdog"]
|
||||
|
6
sample-functions/SentimentAnalysis/build.sh
Executable file
6
sample-functions/SentimentAnalysis/build.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Building functions/sentimentanalysis"
|
||||
docker build -t functions/sentimentanalysis .
|
||||
|
||||
|
17
sample-functions/SentimentAnalysis/handler.py
Normal file
17
sample-functions/SentimentAnalysis/handler.py
Normal file
@ -0,0 +1,17 @@
|
||||
import sys
|
||||
from textblob import TextBlob
|
||||
|
||||
def get_stdin():
|
||||
buf = ""
|
||||
for line in sys.stdin:
|
||||
buf = buf + line
|
||||
return buf
|
||||
|
||||
if(__name__ == "__main__"):
|
||||
st = get_stdin()
|
||||
blob = TextBlob(st)
|
||||
out =""
|
||||
for sentence in blob.sentences:
|
||||
out = out + "Polarity: " + str(sentence.sentiment.polarity) + " Subjectivity: " + str(sentence.sentiment.subjectivity) + "\n"
|
||||
print(out)
|
||||
|
Reference in New Issue
Block a user