Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -62,16 +62,22 @@ def index(files, ds):
|
|
62 |
|
63 |
def convert_files(files):
|
64 |
images = []
|
65 |
-
|
66 |
-
|
67 |
file_path = f['filepath']
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
if len(images) >= 150:
|
76 |
raise gr.Error("The number of images in the dataset should be less than 150.")
|
77 |
return images
|
|
|
62 |
|
63 |
def convert_files(files):
|
64 |
images = []
|
65 |
+
for f in files:
|
66 |
+
if isinstance(f, dict):
|
67 |
file_path = f['filepath']
|
68 |
+
elif isinstance(f, str):
|
69 |
+
file_path = f
|
70 |
+
else:
|
71 |
+
raise TypeError(f"Unsupported file type: {type(f)}")
|
72 |
+
print(f"Processing file: {file_path}")
|
73 |
+
if not os.path.exists(file_path):
|
74 |
+
print(f"File does not exist: {file_path}")
|
75 |
+
continue
|
76 |
+
try:
|
77 |
+
images.extend(pdf2image.convert_from_path(file_path, thread_count=4))
|
78 |
+
except Exception as e:
|
79 |
+
print(f"Error converting {file_path}: {e}")
|
80 |
+
# Handle the error or skip the file
|
81 |
if len(images) >= 150:
|
82 |
raise gr.Error("The number of images in the dataset should be less than 150.")
|
83 |
return images
|