Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from PyPDF2 import PdfReader
|
4 |
-
import PyPDF2
|
5 |
-
import os
|
6 |
import nltk
|
7 |
|
8 |
nltk.download('punkt')
|
|
|
|
|
9 |
|
10 |
def get_pdf_text(pdf_docs):
|
11 |
text = ""
|
@@ -15,35 +15,38 @@ def get_pdf_text(pdf_docs):
|
|
15 |
text += page.extract_text()
|
16 |
return text
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
st.title('Question Generator from PDFs')
|
|
|
|
|
20 |
pipe = pipeline(
|
21 |
task = 'text2text-generation',
|
22 |
model = 'ramsrigouthamg/t5_squad_v1'
|
23 |
)
|
24 |
file = st.file_uploader(label='Upload',accept_multiple_files=True)
|
25 |
-
pr = st.button(label='
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
st.subheader("Generated Questions are: ")
|
35 |
-
s = pipe(sentences)
|
36 |
-
for i in s:
|
37 |
-
questions.append(i['generated_text'][10:])
|
38 |
-
st.write(i['generated_text'][10:])
|
39 |
-
if st.toggle(label='Show Pipeline Output'):
|
40 |
-
st.write(s)
|
41 |
-
if st.toggle(label='Show Questions list'):
|
42 |
-
st.write(questions)
|
43 |
-
# for i in sts:
|
44 |
-
# x = pipe(i)
|
45 |
-
# questions.append(x)
|
46 |
-
# st.write(x)
|
47 |
|
48 |
-
if
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from PyPDF2 import PdfReader
|
|
|
|
|
4 |
import nltk
|
5 |
|
6 |
nltk.download('punkt')
|
7 |
+
st.title(body='7 - Question Generation')
|
8 |
+
|
9 |
|
10 |
def get_pdf_text(pdf_docs):
|
11 |
text = ""
|
|
|
15 |
text += page.extract_text()
|
16 |
return text
|
17 |
|
18 |
+
|
19 |
+
########################################################
|
20 |
+
st.subheader(body='Proposition 1',divider='orange')
|
21 |
+
|
22 |
+
if st.toggle(label='Show Proposition 1'):
|
23 |
st.title('Question Generator from PDFs')
|
24 |
+
if st.checkbox('Show Caption'):
|
25 |
+
st.caption('Hugging Face Model used: ramsrigouthamg/t5_squad_v1')
|
26 |
pipe = pipeline(
|
27 |
task = 'text2text-generation',
|
28 |
model = 'ramsrigouthamg/t5_squad_v1'
|
29 |
)
|
30 |
file = st.file_uploader(label='Upload',accept_multiple_files=True)
|
31 |
+
# pr = st.button(label='Process')
|
32 |
+
raw_text = get_pdf_text(file)
|
33 |
+
sentences = nltk.sent_tokenize(text=raw_text)
|
34 |
+
s = pipe(sentences)
|
35 |
+
questions = []
|
36 |
+
for i in s:
|
37 |
+
x = i['generated_text'][10:]
|
38 |
+
questions.append(x)
|
39 |
+
# st.write(f':blue[{x}]')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
if st.toggle(label='Show Questions'):
|
42 |
+
st.subheader("*Generated Questions are:*")
|
43 |
+
for i in s:
|
44 |
+
x = i['generated_text'][10:]
|
45 |
+
questions.append(x)
|
46 |
+
st.write(f':blue[{x}]')
|
47 |
+
if st.toggle('Show Text'):
|
48 |
+
st.write(raw_text)
|
49 |
+
if st.toggle(label='Show Pipeline Output'):
|
50 |
+
st.write(s)
|
51 |
+
if st.toggle(label='Show Questions list'):
|
52 |
+
st.write(questions)
|