Spaces:
Running
Running
Commit
·
23c47e2
1
Parent(s):
3a522a0
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import os
|
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline
|
4 |
import re
|
5 |
-
from PyPDF2 import
|
6 |
|
7 |
# Function to truncate text to the nearest word boundary
|
8 |
def truncate_to_word_boundary(text, max_words=100):
|
@@ -19,9 +19,9 @@ def question_answering(question, text):
|
|
19 |
return answer
|
20 |
|
21 |
def main():
|
22 |
-
st.title("Question Answering on
|
23 |
|
24 |
-
uploaded_file = st.file_uploader("Upload a file:", type=["pdf", "txt"]) # , "docx", "csv", "json"
|
25 |
question = st.text_input("Ask your question:")
|
26 |
|
27 |
if st.button("Answer") and uploaded_file is not None:
|
@@ -30,11 +30,10 @@ def main():
|
|
30 |
|
31 |
if file_extension == ".pdf":
|
32 |
# Handle PDF files using PyPDF2
|
33 |
-
pdf_reader =
|
34 |
pdf_text = ""
|
35 |
-
for
|
36 |
-
|
37 |
-
pdf_text += pdf_page.extractText()
|
38 |
|
39 |
# Perform question-answering
|
40 |
answer = question_answering(question, pdf_text)
|
|
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline
|
4 |
import re
|
5 |
+
from PyPDF2 import PdfReader
|
6 |
|
7 |
# Function to truncate text to the nearest word boundary
|
8 |
def truncate_to_word_boundary(text, max_words=100):
|
|
|
19 |
return answer
|
20 |
|
21 |
def main():
|
22 |
+
st.title("Question Answering on Uploaded Files")
|
23 |
|
24 |
+
uploaded_file = st.file_uploader("Upload a file:", type=["pdf", "txt"]) # , "docx", "csv", "json", "txt"
|
25 |
question = st.text_input("Ask your question:")
|
26 |
|
27 |
if st.button("Answer") and uploaded_file is not None:
|
|
|
30 |
|
31 |
if file_extension == ".pdf":
|
32 |
# Handle PDF files using PyPDF2
|
33 |
+
pdf_reader = PdfReader(uploaded_file)
|
34 |
pdf_text = ""
|
35 |
+
for pdf_page in pdf_reader.pages:
|
36 |
+
pdf_text += pdf_page.extract_text()
|
|
|
37 |
|
38 |
# Perform question-answering
|
39 |
answer = question_answering(question, pdf_text)
|