JKrishnanandhaa commited on
Commit
3fb30e6
·
verified ·
1 Parent(s): 5433f52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -3
app.py CHANGED
@@ -200,7 +200,30 @@ class ForgeryDetector:
200
  """
201
  # Handle file path input (from gr.Image with type="filepath")
202
  if isinstance(image, str):
203
- if image.lower().endswith('.pdf'):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  # Handle PDF files
205
  import fitz # PyMuPDF
206
  pdf_document = fitz.open(image)
@@ -469,8 +492,8 @@ with gr.Blocks(css=custom_css) as demo:
469
  with gr.Tabs():
470
  with gr.Tab("📤 Upload File"):
471
  input_file = gr.File(
472
- label="Upload Image or PDF",
473
- file_types=["image", ".pdf"],
474
  type="filepath"
475
  )
476
 
 
200
  """
201
  # Handle file path input (from gr.Image with type="filepath")
202
  if isinstance(image, str):
203
+ if image.lower().endswith(('.doc', '.docx')):
204
+ # Handle Word documents - convert to PDF then to image
205
+ try:
206
+ from docx2pdf import convert
207
+ import tempfile
208
+ import os
209
+
210
+ temp_pdf = tempfile.NamedTemporaryFile(delete=False, suffix='.pdf')
211
+ temp_pdf.close()
212
+ convert(image, temp_pdf.name)
213
+
214
+ import fitz
215
+ pdf_document = fitz.open(temp_pdf.name)
216
+ page = pdf_document[0]
217
+ pix = page.get_pixmap(matrix=fitz.Matrix(2, 2))
218
+ image = np.frombuffer(pix.samples, dtype=np.uint8).reshape(pix.height, pix.width, pix.n)
219
+ if pix.n == 4:
220
+ image = cv2.cvtColor(image, cv2.COLOR_RGBA2RGB)
221
+ pdf_document.close()
222
+ os.unlink(temp_pdf.name)
223
+ except Exception as e:
224
+ raise ValueError(f"Could not process Word document: {str(e)}")
225
+
226
+ elif image.lower().endswith('.pdf'):
227
  # Handle PDF files
228
  import fitz # PyMuPDF
229
  pdf_document = fitz.open(image)
 
492
  with gr.Tabs():
493
  with gr.Tab("📤 Upload File"):
494
  input_file = gr.File(
495
+ label="Upload Image, PDF, or Document",
496
+ file_types=["image", ".pdf", ".doc", ".docx"],
497
  type="filepath"
498
  )
499