Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,15 +13,23 @@ import pickle
|
|
13 |
# Function to extract text from a PDF file
|
14 |
def extract_text_from_pdf(pdf_path):
|
15 |
text = ""
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
return text
|
20 |
|
21 |
# Function to extract text from a Word document
|
22 |
def extract_text_from_docx(docx_path):
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
return text
|
26 |
|
27 |
# Initialize the embedding model
|
|
|
13 |
# Function to extract text from a PDF file
|
14 |
def extract_text_from_pdf(pdf_path):
|
15 |
text = ""
|
16 |
+
try:
|
17 |
+
doc = fitz.open(pdf_path)
|
18 |
+
for page_num in range(len(doc)):
|
19 |
+
page = doc.load_page(page_num)
|
20 |
+
text += page.get_text()
|
21 |
+
except Exception as e:
|
22 |
+
print(f"Error extracting text from PDF: {e}")
|
23 |
return text
|
24 |
|
25 |
# Function to extract text from a Word document
|
26 |
def extract_text_from_docx(docx_path):
|
27 |
+
text = ""
|
28 |
+
try:
|
29 |
+
doc = Document(docx_path)
|
30 |
+
text = "\n".join([para.text for para in doc.paragraphs])
|
31 |
+
except Exception as e:
|
32 |
+
print(f"Error extracting text from DOCX: {e}")
|
33 |
return text
|
34 |
|
35 |
# Initialize the embedding model
|