Feat: Integrated uploading file and question generation; needs fixes
This commit is contained in:
parent
3076819535
commit
516b66439f
8
app.py
8
app.py
@ -2,7 +2,7 @@ import os
|
|||||||
from flask import Flask, render_template, redirect, url_for
|
from flask import Flask, render_template, redirect, url_for
|
||||||
from flask.globals import request
|
from flask.globals import request
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
from workers import pdf2text
|
from workers import pdf2text, txt2questions
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
UPLOAD_FOLDER = './pdf/'
|
UPLOAD_FOLDER = './pdf/'
|
||||||
@ -36,16 +36,20 @@ def quiz():
|
|||||||
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()
|
||||||
|
questions = ''
|
||||||
|
|
||||||
# Save uploaded file
|
# Save uploaded file
|
||||||
uploaded_file.save(file_path)
|
uploaded_file.save(file_path)
|
||||||
# Get contents of file
|
# Get contents of file
|
||||||
uploaded_content = pdf2text(file_path, file_exten)
|
uploaded_content = pdf2text(file_path, file_exten)
|
||||||
|
questions = txt2questions(uploaded_content)
|
||||||
|
|
||||||
# File upload + convert success
|
# File upload + convert success
|
||||||
if uploaded_content is not None:
|
if uploaded_content is not None:
|
||||||
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)
|
return render_template('quiz.html', uploaded=UPLOAD_STATUS, questions=questions, size=len(questions))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
1
info.txt
1
info.txt
@ -1 +0,0 @@
|
|||||||
I have worked as a backend developer for creating REST API based based systems and worked with front-end integration for MEAN stack apps. For developing apps with a decoupled architecture. I have focused on security and performance to improve response time. I am well versed in Python, NodeJS and related tools like redis for building and maintaining a scalable architecture. I also have deployed production ready apps used by hundreds of people using AWS EC2, S3 and other cloud based tools. I frequently contribute to open source and support open source tools by creating issues, PRs for tools that I use frequently to try and give back to the community.
|
|
||||||
@ -1,8 +1,39 @@
|
|||||||
|
blis==0.4.1
|
||||||
|
catalogue==1.0.0
|
||||||
|
certifi==2020.6.20
|
||||||
|
chardet==3.0.4
|
||||||
click==7.1.2
|
click==7.1.2
|
||||||
|
cymem==2.0.3
|
||||||
|
en-core-web-md @ https://github.com/explosion/spacy-models/releases/download/en_core_web_md-2.3.1/en_core_web_md-2.3.1.tar.gz
|
||||||
|
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz
|
||||||
Flask==1.1.2
|
Flask==1.1.2
|
||||||
|
gensim==3.8.3
|
||||||
|
idna==2.10
|
||||||
|
importlib-metadata==2.0.0
|
||||||
itsdangerous==1.1.0
|
itsdangerous==1.1.0
|
||||||
Jinja2==2.11.2
|
Jinja2==2.11.2
|
||||||
|
joblib==0.17.0
|
||||||
MarkupSafe==1.1.1
|
MarkupSafe==1.1.1
|
||||||
|
murmurhash==1.0.2
|
||||||
|
nltk==3.5
|
||||||
|
numpy==1.19.2
|
||||||
pkg-resources==0.0.0
|
pkg-resources==0.0.0
|
||||||
|
plac==1.1.3
|
||||||
|
preshed==3.0.2
|
||||||
PyPDF2==1.26.0
|
PyPDF2==1.26.0
|
||||||
|
regex==2020.9.27
|
||||||
|
requests==2.24.0
|
||||||
|
scikit-learn==0.23.2
|
||||||
|
scipy==1.5.2
|
||||||
|
six==1.15.0
|
||||||
|
sklearn==0.0
|
||||||
|
smart-open==3.0.0
|
||||||
|
spacy==2.3.2
|
||||||
|
srsly==1.0.2
|
||||||
|
thinc==7.4.1
|
||||||
|
threadpoolctl==2.1.0
|
||||||
|
tqdm==4.50.2
|
||||||
|
urllib3==1.25.10
|
||||||
|
wasabi==0.8.0
|
||||||
Werkzeug==1.0.1
|
Werkzeug==1.0.1
|
||||||
|
zipp==3.3.0
|
||||||
|
|||||||
@ -1,85 +1,54 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<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') }}"
|
|
||||||
/>
|
|
||||||
<title>MLH Quizzet</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
<head>
|
||||||
<nav
|
<meta charset="UTF-8" />
|
||||||
class="navbar is-dark is-fixed-top has-text-centered"
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
role="navigation"
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.1/css/bulma.min.css" />
|
||||||
aria-label="main navigation"
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/quiz.css') }}" />
|
||||||
>
|
<title>MLH Quizzet</title>
|
||||||
<div class="navbar-brand">
|
</head>
|
||||||
<a class="navbar-item has-text-centered" href="#"
|
|
||||||
><strong class="is-size-3 has-text-centered">Question 1</strong></a
|
<body>
|
||||||
>
|
<nav class="navbar is-dark is-fixed-top has-text-centered" role="navigation" aria-label="main navigation">
|
||||||
<div class="navbar-burger" data-target="navMenu">
|
<div class="navbar-brand">
|
||||||
<span></span>
|
<a class="navbar-item has-text-centered" href="#"><strong class="is-size-3 has-text-centered">MLH
|
||||||
<span></span>
|
Quizzet</strong></a>
|
||||||
<span></span>
|
<div class="navbar-burger" data-target="navMenu">
|
||||||
</div>
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
<span></span>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</div>
|
||||||
<a href="{{ url_for('index') }}"> Home </a>
|
</nav>
|
||||||
{% if uploaded == true %}
|
<a href="{{ url_for('index') }}"> Home </a>
|
||||||
<section class="section-1" id="section-1">
|
{% if uploaded == true %}
|
||||||
<main>
|
|
||||||
<div class="text-container">
|
{% for i in range(size) %}
|
||||||
<h3 class="has-text-weight-bold has-text-black is-size-3">
|
<section class="section-1" id="section-1">
|
||||||
MLH Quizzet
|
<main>
|
||||||
</h3>
|
<p class="has-text-weight-bold has-text-black is-size-2">Question {{ i+1 }}</p>
|
||||||
<p class="has-text-weight-bold has-text-black is-size-4">
|
<div class="text-container">
|
||||||
What does CSS stand for?
|
<p class="has-text-weight-bold has-text-black is-size-4">
|
||||||
</p>
|
{{ questions[i+1]['question'] }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<form>
|
||||||
|
<div class="quiz-options">
|
||||||
|
{% for j in questions[i+1]['options'] %}
|
||||||
|
<input type="radio" class="input-radio one-a" id="one-a" name="yes-1" required />
|
||||||
|
<label class="radio-label" for="one-a">
|
||||||
|
<span class="alphabet">{{ j+1 }}</span> {{ questions[i+1]['options'][j+1] }}
|
||||||
|
<br />
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<form>
|
</form>
|
||||||
<div class="quiz-options">
|
</main>
|
||||||
<input
|
</section>
|
||||||
type="radio"
|
{% endfor %}
|
||||||
class="input-radio one-a"
|
{% else %}
|
||||||
id="one-a"
|
<h1>Could not upload file</h1>
|
||||||
name="yes-1"
|
{% endif %}
|
||||||
required
|
</body>
|
||||||
/>
|
|
||||||
<label class="radio-label" for="one-a">
|
|
||||||
<span class="alphabet">A</span> Cascading Style Sheets
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
class="input-radio one-b"
|
|
||||||
id="one-b"
|
|
||||||
name="yes-1"
|
|
||||||
/>
|
|
||||||
<label class="radio-label" for="one-b">
|
|
||||||
<span class="alphabet">B</span> Creative Screen Styling
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
class="input-radio one-c"
|
|
||||||
id="one-c"
|
|
||||||
name="yes-1"
|
|
||||||
/>
|
|
||||||
<label class="radio-label" for="one-c">
|
|
||||||
<span class="alphabet">C</span> Cascading Style Screen
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</main>
|
|
||||||
</section>
|
|
||||||
{% else %}
|
|
||||||
<h1>Could not upload file</h1>
|
|
||||||
{% endif %}
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
14
workers.py
14
workers.py
@ -1,16 +1,19 @@
|
|||||||
from PyPDF2 import PdfFileReader
|
from PyPDF2 import PdfFileReader
|
||||||
|
from question_generation_main import QuestionGeneration
|
||||||
|
|
||||||
|
|
||||||
def pdf2text(file_path, file_exten) -> str:
|
def pdf2text(file_path, file_exten) -> str:
|
||||||
""" Converts a given file to text content """
|
""" Converts a given file to text content """
|
||||||
|
|
||||||
_content = None
|
_content = ''
|
||||||
|
|
||||||
# Identify file type and get its contents
|
# Identify file type and get its contents
|
||||||
if file_exten == 'pdf':
|
if file_exten == 'pdf':
|
||||||
with open(file_path, 'rb') as pdf_file:
|
with open(file_path, 'rb') as pdf_file:
|
||||||
_pdf_reader = PdfFileReader(pdf_file)
|
_pdf_reader = PdfFileReader(pdf_file)
|
||||||
_content = _pdf_reader
|
# for p in range(_pdf_reader.numPages):
|
||||||
|
# _content += _pdf_reader.getPage(p).extractText()
|
||||||
|
_content = _pdf_reader.getPage(0).extractText()
|
||||||
print('PDF operation done!')
|
print('PDF operation done!')
|
||||||
|
|
||||||
elif file_exten == 'txt':
|
elif file_exten == 'txt':
|
||||||
@ -19,3 +22,10 @@ def pdf2text(file_path, file_exten) -> str:
|
|||||||
print('TXT operation done!')
|
print('TXT operation done!')
|
||||||
|
|
||||||
return _content
|
return _content
|
||||||
|
|
||||||
|
|
||||||
|
def txt2questions(doc, n=1, o=4):
|
||||||
|
""" Get all questions and options """
|
||||||
|
|
||||||
|
qGen = QuestionGeneration(n, o)
|
||||||
|
return qGen.generate_questions_dict(doc)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user