Update app.py
Browse files4 unmodified lines567891014 unmodified lines2526272829303132333435363738394 unmodified linesfrom PyPDF2 import PdfReaderimport osimport torch# Load the LayoutLMv3 model and processorprocessor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base")14 unmodified linesdef process_image(image):try:image = image.convert("RGB")encoded_inputs = processor(image, return_tensors="pt")with torch.no_grad():outputs = model(**encoded_inputs)# Placeholder for table extraction logic# You would implement your table detection and extraction here# For now, we'll just return the shape of the last hidden stateslast_hidden_states = outputs.last_hidden_statereturn f"Image processed. Output shape: {last_hidden_states.shape}"except Exception as e:return f"Error processing image: {str(e)}"4 unmodified lines5678910111214 unmodified lines27282930313233343536373839404142434445464 unmodified linesfrom PyPDF2 import PdfReaderimport osimport torchimport pytesseractfrom pytesseract import TesseractError# Load the LayoutLMv3 model and processorprocessor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base")14 unmodified linesdef process_image(image):try:image = image.convert("RGB")# Use Tesseract to extract text from the imagetry:text = pytesseract.image_to_string(image)except TesseractError as e:return f"Tesseract Error: {str(e)}. Make sure Tesseract is installed and in your PATH."encoded_inputs = processor(image, return_tensors="pt")with torch.no_grad():outputs = model(**encoded_inputs)# For now, we'll just return the extracted text and the shape of the last hidden stateslast_hidden_states = outputs.last_hidden_statereturn f"Extracted Text:\n{text}\n\nImage processed. Output shape: {last_hidden_states.shape}"except Exception as e:return f"Error processing image: {str(e)}"
app.py+11-4