forked from Py-Contributors/awesomeScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
32 lines (27 loc) · 1 KB
/
main.py
File metadata and controls
32 lines (27 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import matplotlib.pyplot as pPlot
from wordcloud import WordCloud, STOPWORDS
from PIL import Image
from flask import Flask, request
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class wordCloudservice(Resource):
def post(self):
ip_json = request.get_json()
# get file name and result filename
wordFile = ip_json["Filename"]
picFile = ip_json["ResultFilename"]
dataset = open(wordFile, "r").read()
# utility function to create wordcloud
def create_word_cloud(string):
cloud = WordCloud(background_color = "white", max_words = 200, stopwords = set(STOPWORDS))
cloud.generate(string)
cloud.to_file(picFile)
dataset = dataset.lower()
create_word_cloud(dataset)
#change path to see word cloud generated
return "Wordcloud can be found at "+picFile,200
# endpoint
api.add_resource(wordCloudservice, '/wordCloudService')
if __name__=='__main__':
app.run(debug=True)