Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -92,20 +92,14 @@ def is_image_file(filename):
|
|
92 |
return any(filename.lower().endswith(ext) for ext in image_file_extensions)
|
93 |
|
94 |
def process_file_and_generate_csv(input_file):
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
#
|
102 |
-
|
103 |
-
if is_image_file(object_name):
|
104 |
-
images.append(Image.open(file_content))
|
105 |
-
file_content.seek(0) # Reset for potential re-use
|
106 |
-
else:
|
107 |
-
# Convert PDF/TIFF to images
|
108 |
-
images.extend(convert_from_path(file_content))
|
109 |
|
110 |
csv_output = BytesIO()
|
111 |
writer = csv.writer(csv_output)
|
|
|
92 |
return any(filename.lower().endswith(ext) for ext in image_file_extensions)
|
93 |
|
94 |
def process_file_and_generate_csv(input_file):
|
95 |
+
# Initialize BytesIO object based on the type of input_file
|
96 |
+
if hasattr(input_file, "read"): # If input_file is file-like
|
97 |
+
file_content = BytesIO(input_file.read())
|
98 |
+
elif isinstance(input_file, str): # If input_file is a string path (unlikely in Gradio but included for completeness)
|
99 |
+
with open(input_file, "rb") as f:
|
100 |
+
file_content = BytesIO(f.read())
|
101 |
+
else: # If input_file is neither (e.g., NamedString), it might directly hold the content
|
102 |
+
file_content = BytesIO(input_file))
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
csv_output = BytesIO()
|
105 |
writer = csv.writer(csv_output)
|