Created
April 24, 2025 20:16
-
-
Save me-suzy/9e6b478a0d93662ccd4534aa3bbbf2c8 to your computer and use it in GitHub Desktop.
OCR 55.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from transformers import TrOCRProcessor, VisionEncoderDecoderModel | |
from PIL import Image | |
# Încarcă modelul și procesorul TrOCR (prima dată îl va descărca) | |
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten") | |
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten") | |
# Încarcă imaginea - înlocuiește cu calea către fișierul tău | |
image_path = "pagina_stanga_pregatita_AI.jpg" | |
image = Image.open(image_path).convert("RGB") | |
# Preprocesează imaginea pentru model | |
pixel_values = processor(images=image, return_tensors="pt").pixel_values | |
# Generează textul | |
generated_ids = model.generate(pixel_values) | |
# Decodează rezultatul | |
extracted_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0] | |
# Afișează textul | |
print("\n--- TEXT EXTRAS ---\n") | |
print(extracted_text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment