Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -83,22 +83,14 @@ def is_image_file(filename):
|
|
83 |
return any(filename.lower().endswith(ext) for ext in image_file_extensions)
|
84 |
|
85 |
def process_file_and_generate_csv(input_file):
|
86 |
-
|
87 |
-
|
88 |
-
# Handling different types of input file objects
|
89 |
-
if hasattr(input_file, 'read'): # If input_file has a read method, it's a file-like object
|
90 |
-
file_content = BytesIO(input_file.read()) # Read file content into memory for processing
|
91 |
-
else: # Assuming input_file might be a path (string) to the uploaded file
|
92 |
-
file_content = open(input_file.name, 'rb') # Open the file for reading in binary mode
|
93 |
-
|
94 |
-
object_name = os.path.basename(input_file.name)
|
95 |
-
|
96 |
images = []
|
97 |
-
if is_image_file(
|
98 |
-
|
99 |
-
|
100 |
else:
|
101 |
-
|
|
|
102 |
|
103 |
csv_output = BytesIO()
|
104 |
writer = csv.writer(csv_output)
|
|
|
83 |
return any(filename.lower().endswith(ext) for ext in image_file_extensions)
|
84 |
|
85 |
def process_file_and_generate_csv(input_file):
|
86 |
+
# Check if the uploaded file is an image or needs conversion to images
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
images = []
|
88 |
+
if is_image_file(input_file.name):
|
89 |
+
input_file.seek(0) # Go to the start of the file
|
90 |
+
images.append(Image.open(input_file))
|
91 |
else:
|
92 |
+
input_file.seek(0) # Ensure we're at the start of the file
|
93 |
+
images.extend(convert_from_bytes(input_file.read()))
|
94 |
|
95 |
csv_output = BytesIO()
|
96 |
writer = csv.writer(csv_output)
|