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,89 +1,91 @@
<!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"
<script src="https://kit.fontawesome.com/22be60108b.js" crossorigin="anonymous"></script> type="image/x-icon">
<title>MLH Quizzet</title> <script src="https://kit.fontawesome.com/22be60108b.js" crossorigin="anonymous"></script>
</head> <title>MLH Quizzet</title>
</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"
<a class="navbar-item has-text-centered" href="{{ url_for('index') }}"><strong style="margin: 10px">
class="is-size-3 has-text-centered">MLH Quizzet</strong></a> <a class="navbar-item has-text-centered" href="{{ url_for('index') }}"><strong
<div class="navbar-burger" data-target="navMenu"> class="is-size-3 has-text-centered">MLH Quizzet</strong></a>
<span></span> <div class="navbar-burger" data-target="navMenu">
<span></span> <span></span>
<span></span> <span></span>
</div> <span></span>
</div>
</nav>
<main role="main">
<div class="card has-text-centered">
<img src="https://cdn4.iconfinder.com/data/icons/files-and-folders-thinline-icons-set/144/File_PDF-512.png"
alt="upload" />
<form action="http://localhost:5000/quiz" method="POST" enctype="multipart/form-data">
<div id="file-js-example" class="file has-name is-fullwidth">
<label class="file-label">
<input class="file-input" type="file" name="file" accept=".txt, application/pdf" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
</span>
<span class="file-label"> Choose a file… </span>
</span>
<span class="file-name"> No file uploaded </span>
</label>
</div> </div>
</div>
</nav>
<main role="main">
<div class="card has-text-centered">
<img src="https://cdn4.iconfinder.com/data/icons/files-and-folders-thinline-icons-set/144/File_PDF-512.png"
alt="upload" />
<form action="http://localhost:5000/quiz" method="POST" enctype="multipart/form-data">
<div id="file-js-example" class="file has-name is-fullwidth">
<label class="file-label">
<input class="file-input" type="file" name="file" accept=".txt, application/pdf" />
<span class="file-cta">
<span class="file-icon">
<i class="fas fa-upload"></i>
</span>
<span class="file-label"> Choose a file… </span>
</span>
<span class="file-name"> No file uploaded </span>
</label>
</div>
<script>
const fileInput = document.querySelector(
"#file-js-example input[type=file]"
);
fileInput.onchange = () => {
if (fileInput.files.length > 0) {
const fileName = document.querySelector(
"#file-js-example .file-name"
);
fileName.textContent = fileInput.files[0].name;
}
};
</script>
<button class="button has-text-centered is-large is-fullwidth is-dark">
<span class="submit has-text-centered" type="submit" name="upload file">Submit</span>
<span class="loading"><i class="fa fa-refresh"></i></span>
<span class="check"><i class="fa fa-check"></i></span>
</button>
</form>
</div>
</main>
<script>const button = document.querySelector('.button');
const submit = document.querySelector('.submit');
<script> function toggleClass() {
const fileInput = document.querySelector( this.classList.toggle('active');
"#file-js-example input[type=file]" }
);
fileInput.onchange = () => {
if (fileInput.files.length > 0) {
const fileName = document.querySelector(
"#file-js-example .file-name"
);
fileName.textContent = fileInput.files[0].name;
}
};
</script>
<button class="button has-text-centered is-large is-fullwidth is-dark">
<span class="submit has-text-centered" type="submit" name="upload file">Submit</span>
<span class="loading"><i class="fa fa-refresh"></i></span>
<span class="check"><i class="fa fa-check"></i></span>
</button>
</form>
</div>
</main>
<script>const button = document.querySelector('.button');
const submit = document.querySelector('.submit');
function toggleClass() { function addClass() {
this.classList.toggle('active'); this.classList.add('finished');
} }
function addClass() { button.addEventListener('click', toggleClass);
this.classList.add('finished'); button.addEventListener('transitionend', toggleClass);
} button.addEventListener('transitionend', addClass);
</script>
</body>
button.addEventListener('click', toggleClass); </html>
button.addEventListener('transitionend', toggleClass);
button.addEventListener('transitionend', addClass);</script>
</body>
</html>

View File

@ -1,78 +1,81 @@
<!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"
<title>MLH Quizzet</title> type="image/x-icon">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type='text/javascript'></script> <title>MLH Quizzet</title>
<script type="text/javascript"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type='text/javascript'></script>
$(document).ready(function () { <script type="text/javascript">
$('label').click(function () { $(document).ready(function () {
$('label').removeClass('worngans'); $('label').click(function () {
$(this).addClass('worngans'); $('label').removeClass('worngans');
$(this).addClass('worngans');
});
}); });
}); </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>
<nav class="navbar is-dark is-fixed-top has-text-centered" role="navigation" aria-label="main navigation"> </style>
<div class="navbar-brand"><img src="https://avatars0.githubusercontent.com/u/65834464?s=200&amp;v=4" height="32" <nav class="navbar is-dark is-fixed-top has-text-centered" role="navigation" aria-label="main navigation">
width="64" style="margin: 7px"> <div class="navbar-brand">
<a class="navbar-item has-text-centered" href="{{ url_for('index') }}"><strong <img src="https://avatars0.githubusercontent.com/u/65834464?s=200&amp;v=4" height="32" width="64"
class="is-size-3 has-text-centered">MLH style="margin: 7px">
Quizzet</strong></a> <a class="navbar-item has-text-centered" href="{{ url_for('index') }}"><strong
<div class="navbar-burger" data-target="navMenu"> class="is-size-3 has-text-centered">MLH
<span></span> Quizzet</strong></a>
<span></span> <div class="navbar-burger" data-target="navMenu">
<span></span> <span></span>
</div> <span></span>
</div> <span></span>
</nav>
{% if uploaded == true %}
{% for i in range(size) %}
<section class="section-1" id="section-1">
<main>
<div class="scp-quizzes-main">
<div class="scp-quizzes-data">
<h3 class="is-size-6 has-text-weight-bold">{{ i+1 }}. {{ questions[i+1]['question'] }}</h3>
<br />
<form>
{% for op in questions[i+1]['options'] %}
{% if op == questions[i+1]['answer'] %}
<input type="radio" id="{{ questions[i+1]['answer'] }}" name="question{{ i+1 }}">
<label for="{{ questions[i+1]['answer'] }}">
{{ op }}</label><br />
{% else %}
<input type="radio" name="question{{ i+1 }}">
<label> {{ op }}</label><br />
{% endif %}
{% endfor %}
</div> </div>
</div> </div>
</form> </nav>
</main> {% if uploaded == true %}
</section> {% for i in range(size) %}
{% endfor %} <section class="section-1" id="section-1">
{% else %} <main>
<section class="section-1" id="section-1"> <div class="scp-quizzes-main">
<h1>Could not upload file</h1> <div class="scp-quizzes-data">
</section> <h3 class="is-size-6 has-text-weight-bold">{{ i+1 }}. {{ questions[i+1]['question'] }}</h3>
{% endif %} <br />
<form>
{% for op in questions[i+1]['options'] %}
{% if op == questions[i+1]['answer'] %}
<input type="radio" id="{{ questions[i+1]['answer'] }}" name="question{{ i+1 }}">
<label for="{{ questions[i+1]['answer'] }}">
{{ op }}</label><br />
{% else %}
<input type="radio" name="question{{ i+1 }}">
<label> {{ op }}</label><br />
{% endif %}
{% endfor %}
</div>
</div>
</form>
</main>
</section>
{% endfor %}
{% else %}
<section class="section-1" id="section-1">
<h1>Could not upload file</h1>
</section>
{% endif %}
<div class="has-text-white has-text-centered"
style="margin-top: 50px; background-color: #363636; padding: 10px;">
MIT License © Copyright 2020 Fantastic Falcons
</div>
</body>
<div class="has-text-white has-text-centered" style="margin-top: 50px; background-color: #363636; padding: 10px;"> </html>
MIT License © Copyright 2020 Fantastic Falcons
</div>
</body>
</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