bluuebunny commited on
Commit
8e157b2
·
verified ·
1 Parent(s): 5a69c8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -9
app.py CHANGED
@@ -110,16 +110,14 @@ def redact_image(pdf_image_path, redaction_score_threshold):
110
  return redacted_image_path
111
 
112
  # Convert the set of redacted images to a pdf
113
- def stich_images_to_pdf(redacted_image_files, input_pdf_name):
114
 
115
  # Sort the redacted images
116
  redacted_image_files.sort()
117
 
118
  # Convert the redacted images to a single PDF
119
  print("Converting redacted images to PDF...")
120
- redacted_pdf_folder = "/tmp/gradio/redacted"
121
- os.makedirs(redacted_pdf_folder, exist_ok=True )
122
- redacted_pdf_path = f'{redacted_pdf_folder}/{input_pdf_name}_redacted.pdf'
123
 
124
  doc = pymupdf.open()
125
  for redacted_image_file in redacted_image_files:
@@ -165,10 +163,6 @@ def predict(input_pdf_path, sensitivity):
165
  # Convert sensitivity to threshold
166
  redaction_score_threshold = (100-sensitivity)/100
167
 
168
- # Get file name
169
- print("Getting filename")
170
- input_pdf_name = input_pdf_path.split('.')[-2]
171
-
172
  # Convert the PDF to images
173
  print("Converting pdf to images")
174
  pdf_images_dir = convert_to_images(input_pdf_path)
@@ -189,7 +183,7 @@ def predict(input_pdf_path, sensitivity):
189
 
190
  # Convert the redacted images to a single PDF
191
  print("Stitching images to pdf")
192
- redacted_pdf_path = stich_images_to_pdf(redacted_image_files, input_pdf_name)
193
 
194
  print("Cleaning up")
195
  cleanup(redacted_image_files, pdf_images, pdf_images_dir, input_pdf_path)
 
110
  return redacted_image_path
111
 
112
  # Convert the set of redacted images to a pdf
113
+ def stich_images_to_pdf(redacted_image_files, input_pdf_path):
114
 
115
  # Sort the redacted images
116
  redacted_image_files.sort()
117
 
118
  # Convert the redacted images to a single PDF
119
  print("Converting redacted images to PDF...")
120
+ redacted_pdf_path = input_pdf_path.replace('.pdf', '_redacted.pdf')
 
 
121
 
122
  doc = pymupdf.open()
123
  for redacted_image_file in redacted_image_files:
 
163
  # Convert sensitivity to threshold
164
  redaction_score_threshold = (100-sensitivity)/100
165
 
 
 
 
 
166
  # Convert the PDF to images
167
  print("Converting pdf to images")
168
  pdf_images_dir = convert_to_images(input_pdf_path)
 
183
 
184
  # Convert the redacted images to a single PDF
185
  print("Stitching images to pdf")
186
+ redacted_pdf_path = stich_images_to_pdf(redacted_image_files, input_pdf_path)
187
 
188
  print("Cleaning up")
189
  cleanup(redacted_image_files, pdf_images, pdf_images_dir, input_pdf_path)