-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
37 lines (26 loc) · 1.24 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
from flask import Flask, request, render_template, current_app, g, redirect
import time
import Levenshtein as minimum_edit_distance
import new_para as paragraphs
app = Flask(__name__)
@app.route('/')
def home() -> 'redirect':
time.sleep(1.5)
return redirect('/entry')
@app.route('/entry')
def entry() -> 'html':
task = paragraphs.random_paragraph() #generates random paragraph of 40 words using openai
return render_template('entry.html', task=task, the_title='Welcome to my site!')
@app.route('/result', methods=['GET', 'POST'])
def result() -> 'html':
user_input = request.form["text"]
completion_time = int(request.form['completion_time'])
words_typed = len(str(user_input).split(' '))
distance = minimum_edit_distance.distance(user_input, task)
# Calculate accuracy (assuming the length of actual_task_text is non-zero)
accuracy = (1 - (distance / len(task))) * 100
accuracy=round(accuracy,2)
typing_speed = words_typed/completion_time*60
return render_template('results.html',the_title='Gautam',completion_time=completion_time, accuracy=accuracy, task=task, user_input=user_input, typing_speed=typing_speed)
if __name__ == '__main__':
app.run(debug=True)