danial0203 commited on
Commit
f01d587
·
verified ·
1 Parent(s): 4631adc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -14
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
- output_csv_path = "output.csv" # Output CSV file name
96
- file_content = BytesIO(input_file.read()) # Read file content into memory for processing
97
- file_content.seek(0) # Go to the start of the file-like object
98
-
99
- object_name = os.path.basename(input_file.name)
100
-
101
- # Check if the uploaded file is an image or needs conversion
102
- images = []
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)