Spaces:
Sleeping
Sleeping
Update app.py
Browse filesMoved model instantiation inside the function
app.py
CHANGED
@@ -2,14 +2,14 @@ from transformers import VisionEncoderDecoderModel
|
|
2 |
from transformers import TrOCRProcessor, AutoTokenizer, ViTImageProcessor
|
3 |
import gradio as gr
|
4 |
|
5 |
-
model = VisionEncoderDecoderModel.from_pretrained("kavg/TrOCR-SIN")
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained('NLPC-UOM/SinBERT-large')
|
7 |
-
feature_extractor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
|
8 |
-
processor = TrOCRProcessor(image_processor=feature_extractor, tokenizer=tokenizer)
|
9 |
-
|
10 |
def OCR(image):
|
11 |
# Load the image
|
12 |
img = Image.open(image)
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
pixel_values = processor(img, return_tensors="pt").pixel_values
|
15 |
generated_ids = model.generate(pixel_values)
|
|
|
2 |
from transformers import TrOCRProcessor, AutoTokenizer, ViTImageProcessor
|
3 |
import gradio as gr
|
4 |
|
|
|
|
|
|
|
|
|
|
|
5 |
def OCR(image):
|
6 |
# Load the image
|
7 |
img = Image.open(image)
|
8 |
+
|
9 |
+
model = VisionEncoderDecoderModel.from_pretrained("kavg/TrOCR-SIN")
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained('NLPC-UOM/SinBERT-large')
|
11 |
+
feature_extractor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
|
12 |
+
processor = TrOCRProcessor(image_processor=feature_extractor, tokenizer=tokenizer)
|
13 |
|
14 |
pixel_values = processor(img, return_tensors="pt").pixel_values
|
15 |
generated_ids = model.generate(pixel_values)
|