-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
62 lines (45 loc) · 1.25 KB
/
app.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Process client requests"""
import os
import datetime
from flask import Flask, request, json
from flask_cors import CORS
from src.slide import Slide
from src.lang import LangChecker
# create app instance with CORS
app = Flask(__name__)
cors = CORS(app)
tool = LangChecker()
# Restful APIs
@app.get('/init/')
def init_worker():
"""Initialize worker to run
Returns:
dict[str,str]: response
"""
return {'status': 200}
@app.post('/slide_analyze/')
def analyze_slide():
"""Extract slide and analyze for improvements
Returns:
dict[str,str]: response
"""
slide = Slide(request.json['url'], datetime.datetime.now().strftime(
'%m_%d_%Y_%H_%M_%S') + '.pptx')
slide.extract_pptx()
info = slide.get_data()
# check for spelling and grammatical errors
tool.analyze_txt(slide.get_txt())
suggestions = tool.get_results()
# delete slide after processing
if os.path.exists(slide.filename):
os.remove(slide.filename)
return {
'slide_count': info[0],
'word_count': json.dumps(info[1]),
'shape_count': info[2],
'font_count': json.dumps(info[3]),
'mistake': json.dumps(suggestions)
}
# main thread
if __name__ == '__main__':
app.run(port=5000)