Update app.py
Browse files
app.py
CHANGED
|
@@ -5,8 +5,6 @@ from pdf2image import convert_from_path
|
|
| 5 |
from PyPDF2 import PdfReader
|
| 6 |
import os
|
| 7 |
import torch
|
| 8 |
-
import pytesseract
|
| 9 |
-
from pytesseract import TesseractError
|
| 10 |
|
| 11 |
# Load the LayoutLMv3 model and processor
|
| 12 |
processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base")
|
|
@@ -28,19 +26,17 @@ def process_image(image):
|
|
| 28 |
try:
|
| 29 |
image = image.convert("RGB")
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
try:
|
| 33 |
-
text = pytesseract.image_to_string(image)
|
| 34 |
-
except TesseractError as e:
|
| 35 |
-
return f"Tesseract Error: {str(e)}. Make sure Tesseract is installed and in your PATH."
|
| 36 |
-
|
| 37 |
encoded_inputs = processor(image, return_tensors="pt")
|
| 38 |
with torch.no_grad():
|
| 39 |
outputs = model(**encoded_inputs)
|
| 40 |
|
| 41 |
-
#
|
| 42 |
last_hidden_states = outputs.last_hidden_state
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
return f"Error processing image: {str(e)}"
|
| 46 |
|
|
|
|
| 5 |
from PyPDF2 import PdfReader
|
| 6 |
import os
|
| 7 |
import torch
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Load the LayoutLMv3 model and processor
|
| 10 |
processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base")
|
|
|
|
| 26 |
try:
|
| 27 |
image = image.convert("RGB")
|
| 28 |
|
| 29 |
+
# Process the image with LayoutLMv3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
encoded_inputs = processor(image, return_tensors="pt")
|
| 31 |
with torch.no_grad():
|
| 32 |
outputs = model(**encoded_inputs)
|
| 33 |
|
| 34 |
+
# Extract relevant information from the model output
|
| 35 |
last_hidden_states = outputs.last_hidden_state
|
| 36 |
+
|
| 37 |
+
# Here you would implement logic to interpret the model output
|
| 38 |
+
# For now, we'll just return some basic information
|
| 39 |
+
return f"Image processed successfully. Output shape: {last_hidden_states.shape}"
|
| 40 |
except Exception as e:
|
| 41 |
return f"Error processing image: {str(e)}"
|
| 42 |
|