hantech commited on
Commit
295589c
·
verified ·
1 Parent(s): 5ad6fc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -62,16 +62,22 @@ def index(files, ds):
62
 
63
  def convert_files(files):
64
  images = []
65
- with tempfile.TemporaryDirectory() as temp_dir:
66
- for f in files:
67
  file_path = f['filepath']
68
- temp_file_path = os.path.join(temp_dir, f['name'])
69
- shutil.copy(file_path, temp_file_path)
70
- try:
71
- images.extend(pdf2image.convert_from_path(temp_file_path, thread_count=4))
72
- except Exception as e:
73
- print(f"Error converting {temp_file_path}: {e}")
74
- # Handle the error, maybe skip the file or raise a Gradio error
 
 
 
 
 
 
75
  if len(images) >= 150:
76
  raise gr.Error("The number of images in the dataset should be less than 150.")
77
  return images
 
62
 
63
  def convert_files(files):
64
  images = []
65
+ for f in files:
66
+ if isinstance(f, dict):
67
  file_path = f['filepath']
68
+ elif isinstance(f, str):
69
+ file_path = f
70
+ else:
71
+ raise TypeError(f"Unsupported file type: {type(f)}")
72
+ print(f"Processing file: {file_path}")
73
+ if not os.path.exists(file_path):
74
+ print(f"File does not exist: {file_path}")
75
+ continue
76
+ try:
77
+ images.extend(pdf2image.convert_from_path(file_path, thread_count=4))
78
+ except Exception as e:
79
+ print(f"Error converting {file_path}: {e}")
80
+ # Handle the error or skip the file
81
  if len(images) >= 150:
82
  raise gr.Error("The number of images in the dataset should be less than 150.")
83
  return images