Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
3 |
-
from PIL import Image
|
4 |
-
|
5 |
-
# Load the model and processor
|
6 |
-
model_name = "microsoft/trocr-large-handwritten"
|
7 |
-
processor = TrOCRProcessor.from_pretrained(model_name)
|
8 |
-
model = VisionEncoderDecoderModel.from_pretrained(model_name)
|
9 |
-
|
10 |
-
def ocr_recognition(image):
|
11 |
-
# Open the image
|
12 |
-
image = Image.open(image).convert("RGB")
|
13 |
-
|
14 |
-
# Process the image and generate text
|
15 |
-
pixel_values = processor(image, return_tensors="pt").pixel_values
|
16 |
-
generated_ids = model.generate(pixel_values)
|
17 |
-
|
18 |
-
# Decode the output text
|
19 |
-
text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
20 |
-
|
21 |
-
return text
|
22 |
-
|
23 |
-
# Create Gradio interface
|
24 |
-
iface = gr.Interface(
|
25 |
-
fn=ocr_recognition,
|
26 |
-
inputs=gr.Image(type="pil"), # Ensures PIL image input
|
27 |
-
outputs="text",
|
28 |
-
title="Handwritten OCR Extraction",
|
29 |
-
description="Upload a handwritten image to extract text using TrOCR."
|
30 |
-
)
|
31 |
-
|
32 |
-
# Launch the Gradio app
|
33 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|