Fix - Formatted code

This commit is contained in:
PragatiVerma18 2020-10-11 14:06:59 +05:30
parent 657c995596
commit e45a7e0a4b
7 changed files with 197 additions and 159 deletions

10
app.py
View File

@ -35,7 +35,9 @@ def quiz():
# Retrieve file from request # Retrieve file from request
uploaded_file = request.files['file'] uploaded_file = request.files['file']
file_path = os.path.join( 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() file_exten = uploaded_file.filename.rsplit('.', 1)[1].lower()
# Save uploaded file # Save uploaded file
@ -50,7 +52,11 @@ def quiz():
UPLOAD_STATUS = True UPLOAD_STATUS = True
except Exception as e: except Exception as e:
print(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__": if __name__ == "__main__":

View File

@ -9,6 +9,7 @@ from nltk.tokenize import sent_tokenize, word_tokenize
import random import random
import numpy as np import numpy as np
class IncorrectAnswerGenerator: class IncorrectAnswerGenerator:
''' This class contains the methods ''' This class contains the methods
for generating the incorrect answers for generating the incorrect answers
@ -35,14 +36,14 @@ class IncorrectAnswerGenerator:
for i in range(1, num_options + 1): for i in range(1, num_options + 1):
options_dict[i] = similar_words[i - 1][0] options_dict[i] = similar_words[i - 1][0]
except: except BaseException:
self.all_sim = [] self.all_sim = []
for word in self.all_words: for word in self.all_words:
if word not in answer: if word not in answer:
try: try:
self.all_sim.append( self.all_sim.append(
(self.model.similarity(answer, word), word)) (self.model.similarity(answer, word), word))
except: except BaseException:
self.all_sim.append( self.all_sim.append(
(0.0, word)) (0.0, word))
else: else:
@ -50,8 +51,8 @@ class IncorrectAnswerGenerator:
self.all_sim.sort(reverse=True) self.all_sim.sort(reverse=True)
for i in range(1, num_options+1): for i in range(1, num_options + 1):
options_dict[i] = self.all_sim[i-1][1] options_dict[i] = self.all_sim[i - 1][1]
replacement_idx = random.randint(1, num_options) replacement_idx = random.randint(1, num_options)

View File

@ -56,6 +56,7 @@ main {
input[type="radio"] { input[type="radio"] {
display: none; display: none;
} }
input[type="radio"] + label { input[type="radio"] + label {
display: inline-block; display: inline-block;
width: 100%; width: 100%;
@ -64,9 +65,11 @@ input[type="radio"] + label {
margin-bottom: 10px; margin-bottom: 10px;
cursor: pointer; cursor: pointer;
} }
input[type="radio"] + label:hover { input[type="radio"] + label:hover {
border: 1px solid #000000; border: 1px solid #000000;
} }
input[type="radio"]:checked + label { input[type="radio"]:checked + label {
background-image: none; background-image: none;
background-color: #0c0; background-color: #0c0;

View File

@ -13,6 +13,7 @@ body {
font-family: "helvetica", sans-serif !important; font-family: "helvetica", sans-serif !important;
overflow-x: hidden !important; overflow-x: hidden !important;
} }
.card { .card {
border-radius: 10px; border-radius: 10px;
margin-top: 100px !important; margin-top: 100px !important;
@ -26,6 +27,7 @@ body {
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.card.has-text-centered h1 { .card.has-text-centered h1 {
font-size: 1.75rem; font-size: 1.75rem;
font-weight: bold; font-weight: bold;
@ -34,9 +36,11 @@ body {
.navbar { .navbar {
margin-bottom: 20px !important; margin-bottom: 20px !important;
} }
.hide { .hide {
display: none; display: none;
} }
.button { .button {
position: relative; position: relative;
display: flex; display: flex;
@ -55,6 +59,7 @@ body {
overflow: hidden; overflow: hidden;
font-family: "Open Sans", sans-serif !important; font-family: "Open Sans", sans-serif !important;
} }
.button:before { .button:before {
position: absolute; position: absolute;
content: ""; content: "";
@ -64,68 +69,86 @@ body {
height: 100%; height: 100%;
background-color: #54d98c; background-color: #54d98c;
} }
.button span { .button span {
position: absolute; position: absolute;
line-height: 0; line-height: 0;
} }
.button span i { .button span i {
transform-origin: center center; transform-origin: center center;
} }
.button span:nth-of-type(1) { .button span:nth-of-type(1) {
top: 50%; top: 50%;
transform: translateY(-50%); transform: translateY(-50%);
} }
.button span:nth-of-type(2) { .button span:nth-of-type(2) {
top: 100%; top: 100%;
transform: translateY(0%); transform: translateY(0%);
font-size: 24px; font-size: 24px;
} }
.button span:nth-of-type(3) { .button span:nth-of-type(3) {
display: none; display: none;
} }
.active { .active {
background-color: #2ecc71; background-color: #2ecc71;
} }
.active:before { .active:before {
width: 100%; width: 100%;
transition: width 30s linear !important; transition: width 30s linear !important;
} }
.active span:nth-of-type(1) { .active span:nth-of-type(1) {
top: -100%; top: -100%;
transform: translateY(-50%); transform: translateY(-50%);
} }
.active span:nth-of-type(2) { .active span:nth-of-type(2) {
top: 50%; top: 50%;
transform: translateY(-50%); transform: translateY(-50%);
} }
.active span:nth-of-type(2) i { .active span:nth-of-type(2) i {
animation: loading 10000ms linear infinite !important; animation: loading 10000ms linear infinite !important;
} }
.active span:nth-of-type(3) { .active span:nth-of-type(3) {
display: none; display: none;
} }
.finished { .finished {
background-color: #54d98c; background-color: #54d98c;
} }
.finished .submit { .finished .submit {
display: none; display: none;
} }
.finished .loading { .finished .loading {
display: none; display: none;
} }
.finished .check { .finished .check {
display: block !important; display: block !important;
font-size: 24px; font-size: 24px;
animation: scale 0.5s linear; animation: scale 0.5s linear;
} }
.finished .check i { .finished .check i {
transform-origin: center center; transform-origin: center center;
} }
@keyframes loading { @keyframes loading {
100% { 100% {
transform: rotate(360deg); transform: rotate(360deg);
} }
} }
@keyframes scale { @keyframes scale {
0% { 0% {
transform: scale(10); transform: scale(10);

View File

@ -1,27 +1,29 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/style.css') }}" /> <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/style.css') }}" />
<link rel="shortcut icon" href="https://avatars0.githubusercontent.com/u/65834464?s=200&amp;v=4" type="image/x-icon"> <link rel="shortcut icon" href="https://avatars0.githubusercontent.com/u/65834464?s=200&amp;v=4"
type="image/x-icon">
<script src="https://kit.fontawesome.com/22be60108b.js" crossorigin="anonymous"></script> <script src="https://kit.fontawesome.com/22be60108b.js" crossorigin="anonymous"></script>
<title>MLH Quizzet</title> <title>MLH Quizzet</title>
</head> </head>
<body> <body>
<style type="text/css"> <style type="text/css">
@font-face { @font-face {
font-family: helvetica; font-family: helvetica;
src: src: "{{ url_for('static', filename='fonts/helvetica.ttf')}}"
"{{ url_for('static', filename='fonts/helvetica.ttf')}}"
} }
</style> </style>
<nav class="navbar is-dark is-fixed-top has-text-centered" role="navigation" aria-label="main navigation"> <nav class="navbar is-dark is-fixed-top has-text-centered" role="navigation" aria-label="main navigation">
<div class="navbar-brand"><img src="https://avatars0.githubusercontent.com/u/65834464?s=200&amp;v=4" height="32" <div class="navbar-brand">
width="64" style="margin: 10px"> <img src="https://avatars0.githubusercontent.com/u/65834464?s=200&amp;v=4" height="32" width="64"
style="margin: 10px">
<a class="navbar-item has-text-centered" href="{{ url_for('index') }}"><strong <a class="navbar-item has-text-centered" href="{{ url_for('index') }}"><strong
class="is-size-3 has-text-centered">MLH Quizzet</strong></a> class="is-size-3 has-text-centered">MLH Quizzet</strong></a>
<div class="navbar-burger" data-target="navMenu"> <div class="navbar-burger" data-target="navMenu">
@ -48,7 +50,6 @@
<span class="file-name"> No file uploaded </span> <span class="file-name"> No file uploaded </span>
</label> </label>
</div> </div>
<script> <script>
const fileInput = document.querySelector( const fileInput = document.querySelector(
"#file-js-example input[type=file]" "#file-js-example input[type=file]"
@ -83,7 +84,8 @@
button.addEventListener('click', toggleClass); button.addEventListener('click', toggleClass);
button.addEventListener('transitionend', toggleClass); button.addEventListener('transitionend', toggleClass);
button.addEventListener('transitionend', addClass);</script> button.addEventListener('transitionend', addClass);
</body> </script>
</body>
</html> </html>

View File

@ -1,12 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/quiz.css') }}" /> <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/quiz.css') }}" />
<link rel="shortcut icon" href="https://avatars0.githubusercontent.com/u/65834464?s=200&amp;v=4" type="image/x-icon"> <link rel="shortcut icon" href="https://avatars0.githubusercontent.com/u/65834464?s=200&amp;v=4"
type="image/x-icon">
<title>MLH Quizzet</title> <title>MLH Quizzet</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type='text/javascript'></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type='text/javascript'></script>
<script type="text/javascript"> <script type="text/javascript">
@ -17,18 +18,20 @@
}); });
}); });
</script> </script>
</head> </head>
<body> <body>
<style type="text/css"> <style type="text/css">
@font-face { @font-face {
font-family: helvetica; font-family: helvetica;
src: "{{ url_for('static', filename='fonts/helvetica.ttf')}}" src: "{{ url_for('static', filename='fonts/helvetica.ttf')}}"
} }
</style> </style>
<nav class="navbar is-dark is-fixed-top has-text-centered" role="navigation" aria-label="main navigation"> <nav class="navbar is-dark is-fixed-top has-text-centered" role="navigation" aria-label="main navigation">
<div class="navbar-brand"><img src="https://avatars0.githubusercontent.com/u/65834464?s=200&amp;v=4" height="32" <div class="navbar-brand">
width="64" style="margin: 7px"> <img src="https://avatars0.githubusercontent.com/u/65834464?s=200&amp;v=4" height="32" width="64"
style="margin: 7px">
<a class="navbar-item has-text-centered" href="{{ url_for('index') }}"><strong <a class="navbar-item has-text-centered" href="{{ url_for('index') }}"><strong
class="is-size-3 has-text-centered">MLH class="is-size-3 has-text-centered">MLH
Quizzet</strong></a> Quizzet</strong></a>
@ -69,10 +72,10 @@
<h1>Could not upload file</h1> <h1>Could not upload file</h1>
</section> </section>
{% endif %} {% endif %}
<div class="has-text-white has-text-centered"
<div class="has-text-white has-text-centered" style="margin-top: 50px; background-color: #363636; padding: 10px;"> style="margin-top: 50px; background-color: #363636; padding: 10px;">
MIT License © Copyright 2020 Fantastic Falcons MIT License © Copyright 2020 Fantastic Falcons
</div> </div>
</body> </body>
</html> </html>

View File

@ -31,8 +31,8 @@ def txt2questions(doc: str, n=5, o=4) -> dict:
q = qGen.generate_questions_dict(doc) q = qGen.generate_questions_dict(doc)
for i in range(len(q)): for i in range(len(q)):
temp = [] temp = []
for j in range(len(q[i+1]['options'])): for j in range(len(q[i + 1]['options'])):
temp.append(q[i+1]['options'][j+1]) temp.append(q[i + 1]['options'][j + 1])
# print(temp) # print(temp)
q[i+1]['options'] = temp q[i + 1]['options'] = temp
return q return q