sblumenf commited on
Commit
e2fb9c7
·
verified ·
1 Parent(s): 28f23fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -12,12 +12,14 @@ import traceback
12
 
13
  def save_image(element, images):
14
  try:
15
- if hasattr(element, 'stream'):
16
  image_data = element.stream.get_rawdata()
17
  image = Image.open(io.BytesIO(image_data))
18
  image_filename = f"extracted_image_{len(images)}.png"
19
  image.save(image_filename)
20
  images.append({"filename": image_filename})
 
 
21
  except Exception as e:
22
  print(f"Error extracting image: {e}")
23
 
@@ -45,6 +47,7 @@ def parse_pdf(pdf_file, output_format, progress=gr.Progress()):
45
  if isinstance(element, LTTextBoxHorizontal):
46
  text += element.get_text()
47
  elif isinstance(element, (LTFigure, LTImage)):
 
48
  save_image(element, images)
49
 
50
  with pdfplumber.open(pdf_file) as pdf:
@@ -115,4 +118,4 @@ iface = gr.Interface(
115
  )
116
 
117
  if __name__ == "__main__":
118
- iface.launch() # Temporarily disable sharing for debugging
 
12
 
13
  def save_image(element, images):
14
  try:
15
+ if hasattr(element, 'stream') and element.stream:
16
  image_data = element.stream.get_rawdata()
17
  image = Image.open(io.BytesIO(image_data))
18
  image_filename = f"extracted_image_{len(images)}.png"
19
  image.save(image_filename)
20
  images.append({"filename": image_filename})
21
+ else:
22
+ print("No stream data for image element")
23
  except Exception as e:
24
  print(f"Error extracting image: {e}")
25
 
 
47
  if isinstance(element, LTTextBoxHorizontal):
48
  text += element.get_text()
49
  elif isinstance(element, (LTFigure, LTImage)):
50
+ print(f"Processing element: {type(element)}")
51
  save_image(element, images)
52
 
53
  with pdfplumber.open(pdf_file) as pdf:
 
118
  )
119
 
120
  if __name__ == "__main__":
121
+ iface.launch() # Temporarily disable sharing for debugging