-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
171 lines (134 loc) · 5.66 KB
/
main.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from flask import Flask, render_template, request,render_template_string,flash
from Writing import ielts
import os
from speaking import Speaking
from score_gen import save_score_plot
import smtplib
import re
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
app = Flask(__name__, template_folder='templates')
app.secret_key = 'your_secret_key'
obj = ielts()
o = Speaking()
@app.route('/')
def index():
return render_template("index.html")
@app.route('/writing', methods=["POST"])
def writing():
return render_template("writing.html")
@app.route('/redirect')
def redirect():
return render_template("writing.html")
@app.route('/writing/evaluate', methods=["POST"])
async def writing_evaluate():
question = request.form["question"]
answer = request.form["answer"]
wordCount = request.form["hiddenWordCount"]
wordCount = re.findall(r'\d+', wordCount)
if answer=='':
return render_template_string('<script>alert("Empty Question/Answer !!");window.location.href="/redirect"</script>')
result = await obj.predictor(question_prompt=question,answer=answer,wordCount=wordCount)
overall = result['predicted_score']
task_achievement = result['task_achievement']
cac = result['Coherence_and_cohesion']
lexical = result['Lexical_resource']
gram = result['Grammatical_range_and_accuracy']
ovs = float(overall['score'])
ovr = overall['remarks']
tas = float(task_achievement['score'])
tar = task_achievement['remarks']
ccs = float(cac['score'])
ccr = cac['remarks']
les = float(lexical['score'])
ler = lexical['remarks']
grs = float(gram['score'])
grr = gram['remarks']
save_score_plot('overall', ovs)
save_score_plot('task_achievement', tas)
save_score_plot('coherence_cohesion', ccs)
save_score_plot('lexical resources', les)
save_score_plot('grammatical', grs)
with open('results.txt','w') as f:
f.write('Question Prompt :\n')
f.write('{}\n\n'.format(question))
f.write('Answer : \n{}\n\n'.format(answer))
f.write('Writing Results :\n')
f.write('Overall:\n\nScore: {}\nRemarks: {}\n'.format(ovs, ovr))
f.write('Task Achievement:\n\nScore: {}\nRemarks: {}\n'.format(tas, tar))
f.write('Coherence and Cohesion:\n\nScore: {}\nRemarks: {}\n'.format(ccs, ccr))
f.write('Lexical Resources:\n\nScore: {}\nRemarks: {}\n'.format(les, ler))
f.write('Grammatical Range and Accuracy:\n\nScore: {}\nRemarks: {}\n'.format(grs, grr))
return render_template("result_writing.html", ovr=ovr, tar=tar, ccr=ccr, ler=ler, grr=grr)
@app.route('/speaking', methods=["POST"])
def speaking():
return render_template('speaking.html')
@app.route('/speaking/upload',methods=["POST"])
def speaking_upload():
uploaded_file = request.files['audio_file']
filename = uploaded_file.filename
ext = os.path.splitext(filename)[1]
newfilename = 'speaking'+ext
uploaded_file.save(os.path.join(app.root_path, 'static', newfilename))
o.stt('static\speaking.mp3')
transcript = open('transcript.txt','r').read()
dialog = o.segment(transcript)
result = o.speaking_predictor(dialog)
gram = result['grammatical_range_and_accuracy']
lexical = result['lexical_resources']
coherence = result['coherence']
overall = result['predicted_score']
gs = float(gram['score'])
ls = float(lexical['score'])
cs = float(coherence['score'])
ovs = float(overall['score'])
gr = gram['remarks']
lr = lexical['remarks']
cr = coherence['remarks']
ovr = overall['remarks']
gc = gram['correction']
lc = lexical['correction']
cc = coherence['correction']
save_score_plot('overalls',ovs)
save_score_plot('coherences',cs)
save_score_plot('lexicals',ls)
save_score_plot('grams',gs)
with open('results.txt','w') as f:
f.write('Speaking Results\n')
f.write('Overall:\n\nScore: {}\nRemarks: {}\n'.format(ovs, ovr))
f.write('Grammatical Range and Accuracy\n\nScore: {}\nRemarks: {}\nCorrection: {}\n'.format(gs, gr, gc))
f.write('Lexical Resources\n\nScore: {}\nRemarks: {}\nCorrection: {}\n'.format(ls, lr, lc))
f.write('Coherence\n\nScore: {}\nRemarks: {}\nCorrection: {}\n'.format(cs, cr, cc))
return render_template("result_speaking.html",gr=gr, lr = lr, cr = cr, ovr = ovr, gc = gc, lc = lc, cc = cc)
@app.route('/result',methods=["POST"])
def result():
return render_template("result.html")
@app.route('/result/send',methods=["POST"])
def send_result():
sender = "[email protected]"
receiver = request.form["email"]
if receiver=='':
return render_template_string('<script>alert("Empty Email.. Fill it !!");window.history.back()</script>')
#create message container
msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = receiver
msg['Subject'] = "IELTS evaluation report"
# add body to email
body = "Please check your IELTS evaluation result"
msg.attach(MIMEText(body, 'plain'))
# add file attachment
with open("results.txt", 'rb') as f:
attachment = MIMEApplication(f.read(), _subtype="txt")
attachment.add_header('Content-Disposition', 'attachment', filename="file.txt")
msg.attach(attachment)
# send the message via Gmail SMTP server
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(sender, "rmwdghaetbjtrfke") # replace "password" with your Gmail account password
server.sendmail(sender, receiver, msg.as_string())
server.quit()
return render_template("index.html")
if __name__ == '__main__':
app.run(debug=True)