-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapp.py
86 lines (65 loc) · 2.5 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
from flask import Flask, request, render_template, redirect, url_for, send_from_directory
from werkzeug.utils import secure_filename
import glob
from uuid import uuid4
import subprocess
from textblob import TextBlob
import docx
from src import checker
from src.extractdoc import scrape_docx
UPLOAD_FOLDER = './test'
ALLOWED_EXTENSIONS = set(['docx'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def serve():
return render_template("index.html")
@app.route('/file', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
if 'file' not in request.files:
print('no file')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
print('no filename')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
text, para_c, sent_c, sent_p_c, total = scrape_docx('./test/' + filename)
corrected, errors = checker.modify(text)
sent=[]
t=TextBlob(corrected)
for sen in t.sentences:
sent.append(str(sen))
doc1 = docx.Document()
print(sent)
ts = 0
for p in range(para_c):
para = ""
for s in range(sent_p_c[p]):
if(ts < total):
print(ts)
para = para + sent[ts] + " "
ts = ts + 1
a = doc1.add_paragraph(para)
doc1.save('RESULT.docx')
return render_template('index.html', correct=corrected, wrong=text, errors=errors)
return render_template('index.html')
@app.route('/text', methods=['GET', 'POST'])
def upload_text():
if request.method == 'POST' and 'textupload' in request.form:
text = request.form['textupload']
corrected, errors = checker.modify(text)
return render_template('index.html', correct=corrected, wrong=text, errors=errors)
return render_template('index.html')
@app.route('/uploads/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
if __name__ == "__main__":
app.run(debug=True)