Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,77 +1,78 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import streamlit as st
|
3 |
-
from pprint import pprint
|
4 |
-
import subprocess
|
5 |
-
cmd = ["python", "-m", "spacy", "download", "en_core_web_sm"]
|
6 |
-
subprocess.run(cmd)
|
7 |
-
from spacy.cli import download
|
8 |
-
from Questgen import main
|
9 |
-
from PyPDF2 import PdfReader
|
10 |
-
from transformers import pipeline
|
11 |
-
from PyPDF2 import PdfReader
|
12 |
-
import nltk
|
13 |
-
import pandas as pd
|
14 |
-
nltk.download('punkt')
|
15 |
-
# st.title(body='7 - Question Generation')
|
16 |
-
|
17 |
-
|
18 |
-
def get_pdf_text(pdf_docs):
|
19 |
-
text = ""
|
20 |
-
for pdf in pdf_docs:
|
21 |
-
pdf_reader = PdfReader(pdf)
|
22 |
-
for page in pdf_reader.pages:
|
23 |
-
text += page.extract_text()
|
24 |
-
return text
|
25 |
-
|
26 |
-
|
27 |
-
########################################################
|
28 |
-
# st.header(body='Proposition 1',divider='red')
|
29 |
-
|
30 |
-
# if st.toggle(label='Show Proposition 1'):
|
31 |
-
st.title('Generate Questions from PDFs')
|
32 |
-
file = st.file_uploader(label='Upload',accept_multiple_files=True)
|
33 |
-
pr = st.button(label='Process')
|
34 |
-
if pr:
|
35 |
-
# pr = st.button(label='Process')
|
36 |
-
raw_text = get_pdf_text(file)
|
37 |
-
# questions = []
|
38 |
-
ge = main.QGen()
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
st.
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
c
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
#
|
66 |
-
df = df
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
77 |
st.write(output)
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import streamlit as st
|
3 |
+
from pprint import pprint
|
4 |
+
import subprocess
|
5 |
+
cmd = ["python", "-m", "spacy", "download", "en_core_web_sm"]
|
6 |
+
subprocess.run(cmd)
|
7 |
+
from spacy.cli import download
|
8 |
+
from Questgen import main, main2
|
9 |
+
from PyPDF2 import PdfReader
|
10 |
+
from transformers import pipeline
|
11 |
+
from PyPDF2 import PdfReader
|
12 |
+
import nltk
|
13 |
+
import pandas as pd
|
14 |
+
nltk.download('punkt')
|
15 |
+
# st.title(body='7 - Question Generation')
|
16 |
+
|
17 |
+
|
18 |
+
def get_pdf_text(pdf_docs):
|
19 |
+
text = ""
|
20 |
+
for pdf in pdf_docs:
|
21 |
+
pdf_reader = PdfReader(pdf)
|
22 |
+
for page in pdf_reader.pages:
|
23 |
+
text += page.extract_text()
|
24 |
+
return text
|
25 |
+
|
26 |
+
|
27 |
+
########################################################
|
28 |
+
# st.header(body='Proposition 1',divider='red')
|
29 |
+
|
30 |
+
# if st.toggle(label='Show Proposition 1'):
|
31 |
+
st.title('Generate Questions from PDFs')
|
32 |
+
file = st.file_uploader(label='Upload',accept_multiple_files=True)
|
33 |
+
pr = st.button(label='Process')
|
34 |
+
if pr:
|
35 |
+
# pr = st.button(label='Process')
|
36 |
+
raw_text = get_pdf_text(file)
|
37 |
+
# questions = []
|
38 |
+
# ge = main.QGen()
|
39 |
+
ge = main2.QGen()
|
40 |
+
payload = {
|
41 |
+
'input_text' : raw_text,
|
42 |
+
# 'max_questions':2,
|
43 |
+
}
|
44 |
+
output = ge.predict_mcq(payload=payload)
|
45 |
+
st.header(body='*Generated Questions are:*', divider='orange')
|
46 |
+
for question in output['questions']:
|
47 |
+
st.subheader(body=f":orange[Q{question['id']}:] {question['question_statement']}", divider='blue')
|
48 |
+
st.markdown(f"A: {question['answer']}")
|
49 |
+
c = 0
|
50 |
+
for option in question['options']:
|
51 |
+
# st.markdown(f"{c}")
|
52 |
+
c+=1
|
53 |
+
if c==1:
|
54 |
+
st.markdown(f"B: {option}")
|
55 |
+
elif c==2:
|
56 |
+
st.markdown(f"C: {option}")
|
57 |
+
elif c==3:
|
58 |
+
st.markdown(f"D: {option}")
|
59 |
+
|
60 |
+
|
61 |
+
if output is not None:
|
62 |
+
# Convert the dictionary to a DataFrame
|
63 |
+
df = pd.DataFrame(output['questions'])
|
64 |
+
|
65 |
+
# Convert the options from lists to strings
|
66 |
+
# df['options'] = df['options'].apply(lambda x: ','.join(x))
|
67 |
+
df = df.drop(labels=['options_algorithm','extra_options','context','question_type'],axis=1)
|
68 |
+
# Convert the DataFrame to CSV
|
69 |
+
csv = df.to_csv(index=False).encode('utf-8')
|
70 |
+
st.download_button(
|
71 |
+
label='Download Data',
|
72 |
+
data=csv,
|
73 |
+
file_name='Generated MCQs.csv',
|
74 |
+
mime='text/csv'
|
75 |
+
)
|
76 |
+
|
77 |
+
if st.toggle(label='Show Raw Output'):
|
78 |
st.write(output)
|