Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,7 +40,11 @@ def extract_text_from_pdf(pdf_file):
|
|
40 |
with pdfplumber.open(pdf_file) as pdf:
|
41 |
text = ""
|
42 |
for page in pdf.pages:
|
43 |
-
|
|
|
|
|
|
|
|
|
44 |
return text
|
45 |
|
46 |
# Split text into sentences for better matching
|
@@ -59,12 +63,17 @@ pdf_embeddings = None
|
|
59 |
|
60 |
if pdf_file:
|
61 |
pdf_text = extract_text_from_pdf(pdf_file)
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
st.
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
# User input for chatbot
|
70 |
user_input = st.text_input("Ask a question about the PDF:")
|
@@ -90,3 +99,4 @@ if st.button("Get Response"):
|
|
90 |
except Exception as e:
|
91 |
st.error(f"Error while processing user input: {e}")
|
92 |
|
|
|
|
40 |
with pdfplumber.open(pdf_file) as pdf:
|
41 |
text = ""
|
42 |
for page in pdf.pages:
|
43 |
+
page_text = page.extract_text()
|
44 |
+
if page_text: # Check if page text is not empty
|
45 |
+
text += page_text + "\n" # Add newline for better separation
|
46 |
+
else:
|
47 |
+
st.warning("No extractable text found on a page.")
|
48 |
return text
|
49 |
|
50 |
# Split text into sentences for better matching
|
|
|
63 |
|
64 |
if pdf_file:
|
65 |
pdf_text = extract_text_from_pdf(pdf_file)
|
66 |
+
|
67 |
+
# Check if the extracted text is empty
|
68 |
+
if not pdf_text.strip():
|
69 |
+
st.error("The extracted PDF text is empty. Please upload a PDF with extractable text.")
|
70 |
+
else:
|
71 |
+
try:
|
72 |
+
pdf_sentences = split_text_into_sentences(pdf_text) # Split PDF text into sentences
|
73 |
+
pdf_embeddings = np.array([get_embeddings(sentence) for sentence in pdf_sentences]) # Get embeddings for each sentence
|
74 |
+
st.success("PDF loaded successfully!")
|
75 |
+
except Exception as e:
|
76 |
+
st.error(f"Error while processing PDF: {e}")
|
77 |
|
78 |
# User input for chatbot
|
79 |
user_input = st.text_input("Ask a question about the PDF:")
|
|
|
99 |
except Exception as e:
|
100 |
st.error(f"Error while processing user input: {e}")
|
101 |
|
102 |
+
|