Update app.py
Browse files
app.py
CHANGED
|
@@ -124,16 +124,22 @@ class ForgeryDetector:
|
|
| 124 |
gauge_accuracy: Accuracy gauge
|
| 125 |
results_html: Detection results as HTML
|
| 126 |
"""
|
| 127 |
-
# Handle
|
| 128 |
-
if isinstance(image, str)
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
image =
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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):
|