Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,8 +6,8 @@ from transformers import MllamaForConditionalGeneration, AutoProcessor
|
|
| 6 |
from PyPDF2 import PdfReader
|
| 7 |
import tempfile
|
| 8 |
import os
|
| 9 |
-
|
| 10 |
-
token=os.getenv("HF_TOKEN")
|
| 11 |
# Model and processor setup
|
| 12 |
model_id = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
| 13 |
|
|
@@ -22,19 +22,11 @@ processor = AutoProcessor.from_pretrained(model_id)
|
|
| 22 |
|
| 23 |
def process_pdf(pdf_file):
|
| 24 |
"""Extract text from each page of a PDF."""
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
temp_pdf.write(pdf_file.read())
|
| 28 |
-
temp_pdf_path = temp_pdf.name
|
| 29 |
-
|
| 30 |
-
# Read the PDF
|
| 31 |
-
pdf_reader = PdfReader(temp_pdf_path)
|
| 32 |
extracted_text = {}
|
| 33 |
|
| 34 |
-
for i,
|
| 35 |
-
# Convert page content to an image (placeholder: replace with actual PDF-to-image conversion)
|
| 36 |
-
page_image = Image.new("RGB", (1000, 1000), color=(255, 255, 255))
|
| 37 |
-
|
| 38 |
# Define the instruction for OCR
|
| 39 |
messages = [
|
| 40 |
{"role": "user", "content": [
|
|
|
|
| 6 |
from PyPDF2 import PdfReader
|
| 7 |
import tempfile
|
| 8 |
import os
|
| 9 |
+
from pdf2image import convert_from_path
|
| 10 |
+
token= os.getenv("HF_TOKEN")
|
| 11 |
# Model and processor setup
|
| 12 |
model_id = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
| 13 |
|
|
|
|
| 22 |
|
| 23 |
def process_pdf(pdf_file):
|
| 24 |
"""Extract text from each page of a PDF."""
|
| 25 |
+
# Read the PDF using pdf2image to convert pages to images
|
| 26 |
+
images = convert_from_path(pdf_file.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
extracted_text = {}
|
| 28 |
|
| 29 |
+
for i, page_image in enumerate(images):
|
|
|
|
|
|
|
|
|
|
| 30 |
# Define the instruction for OCR
|
| 31 |
messages = [
|
| 32 |
{"role": "user", "content": [
|