danial0203 commited on
Commit
562d36e
1 Parent(s): 61167a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -76,16 +76,16 @@ def get_text(result, blocks_map):
76
  if word['SelectionStatus'] == 'SELECTED':
77
  text += 'X '
78
  return text.strip()
79
-
80
- def process_file_and_generate_csv(file):
81
- # Directly use the file path provided by Gradio
82
- file_path = file.name if isinstance(file, gr.files.File) else file
83
 
84
  csv_output_path = "/tmp/output.csv"
85
 
86
  if file_path.lower().endswith(('.png', '.jpg', '.jpeg')):
87
  images = [Image.open(file_path)]
88
  else:
 
89
  images = convert_from_path(file_path)
90
 
91
  for i, image in enumerate(images):
@@ -99,10 +99,13 @@ def process_file_and_generate_csv(file):
99
  tables = [block for block in blocks if block['BlockType'] == "TABLE"]
100
  generate_table_csv(tables, blocks_map, csv_output_path)
101
 
102
- # Return the CSV output path for Gradio to handle the file download
 
 
103
  return csv_output_path, "Processing completed successfully!"
104
 
105
 
 
106
  # Gradio Interface
107
  iface = gr.Interface(
108
  fn=process_file_and_generate_csv,
 
76
  if word['SelectionStatus'] == 'SELECTED':
77
  text += 'X '
78
  return text.strip()
79
+
80
+ def process_file_and_generate_csv(file_path):
81
+ # The file_path is directly usable; no need to check for attributes or methods
 
82
 
83
  csv_output_path = "/tmp/output.csv"
84
 
85
  if file_path.lower().endswith(('.png', '.jpg', '.jpeg')):
86
  images = [Image.open(file_path)]
87
  else:
88
+ # Convert PDF or other supported formats to images
89
  images = convert_from_path(file_path)
90
 
91
  for i, image in enumerate(images):
 
99
  tables = [block for block in blocks if block['BlockType'] == "TABLE"]
100
  generate_table_csv(tables, blocks_map, csv_output_path)
101
 
102
+ # No need to remove the original file_path; Gradio handles temporary file cleanup
103
+
104
+ # Return the CSV output path and a success message for Gradio to handle
105
  return csv_output_path, "Processing completed successfully!"
106
 
107
 
108
+
109
  # Gradio Interface
110
  iface = gr.Interface(
111
  fn=process_file_and_generate_csv,