JKrishnanandhaa commited on
Commit
5f84c07
·
verified ·
1 Parent(s): 1dd4d9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -124,16 +124,22 @@ class ForgeryDetector:
124
  gauge_accuracy: Accuracy gauge
125
  results_html: Detection results as HTML
126
  """
127
- # Handle PDF files
128
- if isinstance(image, str) and image.lower().endswith('.pdf'):
129
- import fitz # PyMuPDF
130
- pdf_document = fitz.open(image)
131
- page = pdf_document[0]
132
- pix = page.get_pixmap(matrix=fitz.Matrix(2, 2))
133
- image = np.frombuffer(pix.samples, dtype=np.uint8).reshape(pix.height, pix.width, pix.n)
134
- if pix.n == 4:
135
- image = cv2.cvtColor(image, cv2.COLOR_RGBA2RGB)
136
- pdf_document.close()
 
 
 
 
 
 
137
 
138
  # Convert PIL to numpy
139
  if isinstance(image, Image.Image):
 
124
  gauge_accuracy: Accuracy gauge
125
  results_html: Detection results as HTML
126
  """
127
+ # Handle file path input (from gr.Image with type="filepath")
128
+ if isinstance(image, str):
129
+ if image.lower().endswith('.pdf'):
130
+ # Handle PDF files
131
+ import fitz # PyMuPDF
132
+ pdf_document = fitz.open(image)
133
+ page = pdf_document[0]
134
+ pix = page.get_pixmap(matrix=fitz.Matrix(2, 2))
135
+ image = np.frombuffer(pix.samples, dtype=np.uint8).reshape(pix.height, pix.width, pix.n)
136
+ if pix.n == 4:
137
+ image = cv2.cvtColor(image, cv2.COLOR_RGBA2RGB)
138
+ pdf_document.close()
139
+ else:
140
+ # Load image file
141
+ image = Image.open(image)
142
+ image = np.array(image)
143
 
144
  # Convert PIL to numpy
145
  if isinstance(image, Image.Image):