Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,13 +7,12 @@ import PyPDF2
|
|
7 |
import streamlit as st
|
8 |
|
9 |
# Function to extract text from PDF
|
10 |
-
def extract_text_from_pdf(
|
11 |
pdf_text = ""
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
pdf_text += page.extract_text()
|
17 |
return pdf_text
|
18 |
|
19 |
# Initialize the tokenizer and model
|
@@ -34,7 +33,6 @@ prompt = """
|
|
34 |
Based on the following context/document:
|
35 |
{}
|
36 |
Please answer the question: {}
|
37 |
-
|
38 |
### Response:
|
39 |
{}
|
40 |
"""
|
@@ -63,7 +61,7 @@ def generate_answer(context, query):
|
|
63 |
st.title("RAG-Based PDF Question Answering Application")
|
64 |
|
65 |
# Upload PDF
|
66 |
-
uploaded_file = st.file_uploader("
|
67 |
|
68 |
if uploaded_file is not None:
|
69 |
# Extract text from the uploaded PDF
|
|
|
7 |
import streamlit as st
|
8 |
|
9 |
# Function to extract text from PDF
|
10 |
+
def extract_text_from_pdf(uploaded_file):
|
11 |
pdf_text = ""
|
12 |
+
reader = PyPDF2.PdfReader(uploaded_file)
|
13 |
+
for page_num in range(len(reader.pages)):
|
14 |
+
page = reader.pages[page_num]
|
15 |
+
pdf_text += page.extract_text()
|
|
|
16 |
return pdf_text
|
17 |
|
18 |
# Initialize the tokenizer and model
|
|
|
33 |
Based on the following context/document:
|
34 |
{}
|
35 |
Please answer the question: {}
|
|
|
36 |
### Response:
|
37 |
{}
|
38 |
"""
|
|
|
61 |
st.title("RAG-Based PDF Question Answering Application")
|
62 |
|
63 |
# Upload PDF
|
64 |
+
uploaded_file = st.file_uploader("Upload a PDF file", type="pdf")
|
65 |
|
66 |
if uploaded_file is not None:
|
67 |
# Extract text from the uploaded PDF
|