danial0203 commited on
Commit
8cd0fcc
·
verified ·
1 Parent(s): e003f08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -14
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
- output_csv_path = "output.csv" # Output CSV file name
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(object_name):
98
- images.append(Image.open(file_content))
99
- file_content.seek(0) # Reset for potential re-use
100
  else:
101
- images.extend(convert_from_path(file_content))
 
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)