File size: 896 Bytes
c6111b8
9164d6d
c6111b8
 
 
9164d6d
 
 
c6111b8
9164d6d
c6111b8
 
9164d6d
c6111b8
 
 
 
9164d6d
c6111b8
9164d6d
c6111b8
9164d6d
 
 
c6111b8
 
9164d6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
from PIL import Image
import requests

# Load your model from Hugging Face
processor = TrOCRProcessor.from_pretrained("DeepDiveDev/transformodocs-ocr")
model = VisionEncoderDecoderModel.from_pretrained("DeepDiveDev/transformodocs-ocr")

# Function to extract text
def extract_text(image):
    image = Image.open(image).convert("RGB")
    pixel_values = processor(images=image, return_tensors="pt").pixel_values
    generated_ids = model.generate(pixel_values)
    extracted_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
    return extracted_text

# Gradio Interface
iface = gr.Interface(
    fn=extract_text,
    inputs="image",
    outputs="text",
    title="TransformoDocs - AI OCR",
    description="Upload a handwritten document and get the extracted text.",
)

iface.launch()