From e45a7e0a4b9639b70d639bbc1faa68daf15126f4 Mon Sep 17 00:00:00 2001 From: PragatiVerma18 Date: Sun, 11 Oct 2020 14:06:59 +0530 Subject: [PATCH] Fix - Formatted code --- app.py | 10 +- incorrect_answer_generation.py | 9 +- static/css/quiz.css | 3 + static/css/style.css | 23 +++++ templates/index.html | 162 +++++++++++++++++---------------- templates/quiz.html | 143 +++++++++++++++-------------- workers.py | 6 +- 7 files changed, 197 insertions(+), 159 deletions(-) diff --git a/app.py b/app.py index c25bd80..1ee0138 100644 --- a/app.py +++ b/app.py @@ -35,7 +35,9 @@ def quiz(): # Retrieve file from request uploaded_file = request.files['file'] file_path = os.path.join( - app.config['UPLOAD_FOLDER'], secure_filename(uploaded_file.filename)) + app.config['UPLOAD_FOLDER'], + secure_filename( + uploaded_file.filename)) file_exten = uploaded_file.filename.rsplit('.', 1)[1].lower() # Save uploaded file @@ -50,7 +52,11 @@ def quiz(): UPLOAD_STATUS = True except Exception as e: print(e) - return render_template('quiz.html', uploaded=UPLOAD_STATUS, questions=questions, size=len(questions)) + return render_template( + 'quiz.html', + uploaded=UPLOAD_STATUS, + questions=questions, + size=len(questions)) if __name__ == "__main__": diff --git a/incorrect_answer_generation.py b/incorrect_answer_generation.py index b1e0f4f..149dd43 100644 --- a/incorrect_answer_generation.py +++ b/incorrect_answer_generation.py @@ -9,6 +9,7 @@ from nltk.tokenize import sent_tokenize, word_tokenize import random import numpy as np + class IncorrectAnswerGenerator: ''' This class contains the methods for generating the incorrect answers @@ -35,14 +36,14 @@ class IncorrectAnswerGenerator: for i in range(1, num_options + 1): options_dict[i] = similar_words[i - 1][0] - except: + except BaseException: self.all_sim = [] for word in self.all_words: if word not in answer: try: self.all_sim.append( (self.model.similarity(answer, word), word)) - except: + except BaseException: self.all_sim.append( (0.0, word)) else: @@ -50,8 +51,8 @@ class IncorrectAnswerGenerator: self.all_sim.sort(reverse=True) - for i in range(1, num_options+1): - options_dict[i] = self.all_sim[i-1][1] + for i in range(1, num_options + 1): + options_dict[i] = self.all_sim[i - 1][1] replacement_idx = random.randint(1, num_options) diff --git a/static/css/quiz.css b/static/css/quiz.css index e4ef607..a1845dc 100644 --- a/static/css/quiz.css +++ b/static/css/quiz.css @@ -56,6 +56,7 @@ main { input[type="radio"] { display: none; } + input[type="radio"] + label { display: inline-block; width: 100%; @@ -64,9 +65,11 @@ input[type="radio"] + label { margin-bottom: 10px; cursor: pointer; } + input[type="radio"] + label:hover { border: 1px solid #000000; } + input[type="radio"]:checked + label { background-image: none; background-color: #0c0; diff --git a/static/css/style.css b/static/css/style.css index 31dec16..76b4d54 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -13,6 +13,7 @@ body { font-family: "helvetica", sans-serif !important; overflow-x: hidden !important; } + .card { border-radius: 10px; margin-top: 100px !important; @@ -26,6 +27,7 @@ body { justify-content: center; align-items: center; } + .card.has-text-centered h1 { font-size: 1.75rem; font-weight: bold; @@ -34,9 +36,11 @@ body { .navbar { margin-bottom: 20px !important; } + .hide { display: none; } + .button { position: relative; display: flex; @@ -55,6 +59,7 @@ body { overflow: hidden; font-family: "Open Sans", sans-serif !important; } + .button:before { position: absolute; content: ""; @@ -64,68 +69,86 @@ body { height: 100%; background-color: #54d98c; } + .button span { position: absolute; line-height: 0; } + .button span i { transform-origin: center center; } + .button span:nth-of-type(1) { top: 50%; transform: translateY(-50%); } + .button span:nth-of-type(2) { top: 100%; transform: translateY(0%); font-size: 24px; } + .button span:nth-of-type(3) { display: none; } + .active { background-color: #2ecc71; } + .active:before { width: 100%; transition: width 30s linear !important; } + .active span:nth-of-type(1) { top: -100%; transform: translateY(-50%); } + .active span:nth-of-type(2) { top: 50%; transform: translateY(-50%); } + .active span:nth-of-type(2) i { animation: loading 10000ms linear infinite !important; } + .active span:nth-of-type(3) { display: none; } + .finished { background-color: #54d98c; } + .finished .submit { display: none; } + .finished .loading { display: none; } + .finished .check { display: block !important; font-size: 24px; animation: scale 0.5s linear; } + .finished .check i { transform-origin: center center; } + @keyframes loading { 100% { transform: rotate(360deg); } } + @keyframes scale { 0% { transform: scale(10); diff --git a/templates/index.html b/templates/index.html index 7244376..66062c2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,89 +1,91 @@ - - - - - - - - MLH Quizzet - + + + + + + + + MLH Quizzet + - - - -
-
- upload -
-
- + + + +
+
+ upload + +
+ +
+ + + +
+
+ - - -
-
- + - button.addEventListener('click', toggleClass); - button.addEventListener('transitionend', toggleClass); - button.addEventListener('transitionend', addClass); - - - \ No newline at end of file + diff --git a/templates/quiz.html b/templates/quiz.html index 53b62ea..103fb66 100644 --- a/templates/quiz.html +++ b/templates/quiz.html @@ -1,78 +1,81 @@ - - - - - - - MLH Quizzet - - + - + + - - - - {% if uploaded == true %} - {% for i in range(size) %} -
-
-
-
-

{{ i+1 }}. {{ questions[i+1]['question'] }}

-
-
- {% for op in questions[i+1]['options'] %} - {% if op == questions[i+1]['answer'] %} - -
- {% else %} - -
- {% endif %} - {% endfor %} + + +
-
- {% endfor %} - {% else %} -
-

Could not upload file

-
- {% endif %} + + {% if uploaded == true %} + {% for i in range(size) %} +
+
+
+
+

{{ i+1 }}. {{ questions[i+1]['question'] }}

+
+
+ {% for op in questions[i+1]['options'] %} + {% if op == questions[i+1]['answer'] %} + +
+ {% else %} + +
+ {% endif %} + {% endfor %} +
+
+ +
+
+ {% endfor %} + {% else %} +
+

Could not upload file

+
+ {% endif %} +
+ MIT License © Copyright 2020 Fantastic Falcons +
+ -
-MIT License © Copyright 2020 Fantastic Falcons -
- - - \ No newline at end of file + diff --git a/workers.py b/workers.py index 52ea0d3..953b32a 100644 --- a/workers.py +++ b/workers.py @@ -31,8 +31,8 @@ def txt2questions(doc: str, n=5, o=4) -> dict: q = qGen.generate_questions_dict(doc) for i in range(len(q)): temp = [] - for j in range(len(q[i+1]['options'])): - temp.append(q[i+1]['options'][j+1]) + for j in range(len(q[i + 1]['options'])): + temp.append(q[i + 1]['options'][j + 1]) # print(temp) - q[i+1]['options'] = temp + q[i + 1]['options'] = temp return q