Spaces:
Sleeping
Sleeping
CHANGE: replace pymupdf with pdfplumber
Browse files- data.py +5 -5
- requirement.txt +1 -1
data.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
-
import fitz
|
| 2 |
import os
|
|
|
|
| 3 |
|
| 4 |
def load_text(path):
|
| 5 |
file_extension = os.path.splitext(path)[1].lower()
|
| 6 |
-
|
| 7 |
if file_extension == ".pdf":
|
| 8 |
-
doc = fitz.open(path)
|
| 9 |
texts = []
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
return "\n".join(texts)
|
| 13 |
|
| 14 |
elif file_extension == ".txt":
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import pdfplumber
|
| 3 |
|
| 4 |
def load_text(path):
|
| 5 |
file_extension = os.path.splitext(path)[1].lower()
|
| 6 |
+
|
| 7 |
if file_extension == ".pdf":
|
|
|
|
| 8 |
texts = []
|
| 9 |
+
with pdfplumber.open(path) as pdf:
|
| 10 |
+
for page in pdf.pages:
|
| 11 |
+
texts.append(page.extract_text() or "")
|
| 12 |
return "\n".join(texts)
|
| 13 |
|
| 14 |
elif file_extension == ".txt":
|
requirement.txt
CHANGED
|
@@ -5,7 +5,7 @@ torch==1.13.1
|
|
| 5 |
torchaudio==0.13.1
|
| 6 |
torchvision==0.14.1
|
| 7 |
faiss-cpu==1.9.0
|
| 8 |
-
|
| 9 |
|
| 10 |
# Web UI
|
| 11 |
gradio==3.50.2
|
|
|
|
| 5 |
torchaudio==0.13.1
|
| 6 |
torchvision==0.14.1
|
| 7 |
faiss-cpu==1.9.0
|
| 8 |
+
pdfplumber
|
| 9 |
|
| 10 |
# Web UI
|
| 11 |
gradio==3.50.2
|