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
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__":

View File

@ -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)

View File

@ -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;

View File

@ -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);

View File

@ -1,89 +1,91 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<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" 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">
<script src="https://kit.fontawesome.com/22be60108b.js" crossorigin="anonymous"></script>
<title>MLH Quizzet</title>
</head>
<head>
<meta charset="UTF-8" />
<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" 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">
<script src="https://kit.fontawesome.com/22be60108b.js" crossorigin="anonymous"></script>
<title>MLH Quizzet</title>
</head>
<body>
<style type="text/css">
@font-face {
font-family: helvetica;
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">
<div class="navbar-brand"><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
class="is-size-3 has-text-centered">MLH Quizzet</strong></a>
<div class="navbar-burger" data-target="navMenu">
<span></span>
<span></span>
<span></span>
</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>
<body>
<style type="text/css">
@font-face {
font-family: helvetica;
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">
<div class="navbar-brand">
<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
class="is-size-3 has-text-centered">MLH Quizzet</strong></a>
<div class="navbar-burger" data-target="navMenu">
<span></span>
<span></span>
<span></span>
</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>
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');
function toggleClass() {
this.classList.toggle('active');
}
function toggleClass() {
this.classList.toggle('active');
}
function addClass() {
this.classList.add('finished');
}
function addClass() {
this.classList.add('finished');
}
button.addEventListener('click', toggleClass);
button.addEventListener('transitionend', toggleClass);
button.addEventListener('transitionend', addClass);
</script>
</body>
button.addEventListener('click', toggleClass);
button.addEventListener('transitionend', toggleClass);
button.addEventListener('transitionend', addClass);</script>
</body>
</html>
</html>

View File

@ -1,78 +1,81 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<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" 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">
<title>MLH Quizzet</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type='text/javascript'></script>
<script type="text/javascript">
$(document).ready(function () {
$('label').click(function () {
$('label').removeClass('worngans');
$(this).addClass('worngans');
<head>
<meta charset="UTF-8" />
<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" 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">
<title>MLH Quizzet</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type='text/javascript'></script>
<script type="text/javascript">
$(document).ready(function () {
$('label').click(function () {
$('label').removeClass('worngans');
$(this).addClass('worngans');
});
});
});
</script>
</head>
</script>
</head>
<body>
<style type="text/css">
@font-face {
font-family: helvetica;
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">
<div class="navbar-brand"><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
class="is-size-3 has-text-centered">MLH
Quizzet</strong></a>
<div class="navbar-burger" data-target="navMenu">
<span></span>
<span></span>
<span></span>
</div>
</div>
</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 %}
<body>
<style type="text/css">
@font-face {
font-family: helvetica;
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">
<div class="navbar-brand">
<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
class="is-size-3 has-text-centered">MLH
Quizzet</strong></a>
<div class="navbar-burger" data-target="navMenu">
<span></span>
<span></span>
<span></span>
</div>
</div>
</form>
</main>
</section>
{% endfor %}
{% else %}
<section class="section-1" id="section-1">
<h1>Could not upload file</h1>
</section>
{% endif %}
</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>
</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;">
MIT License © Copyright 2020 Fantastic Falcons
</div>
</body>
</html>
</html>

View File

@ -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