Spaces:
Running
Running
Create app.py
Browse filesInitial commit
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import VisionEncoderDecoderModel
|
2 |
+
from transformers import TrOCRProcessor, AutoTokenizer, ViTImageProcessor
|
3 |
+
import gradio as gr
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
def OCR(image):
|
7 |
+
|
8 |
+
model = VisionEncoderDecoderModel.from_pretrained("kavg/TrOCR-SIN-DeiT")
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained('NLPC-UOM/SinBERT-large')
|
10 |
+
feature_extractor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
|
11 |
+
processor = TrOCRProcessor(image_processor=feature_extractor, tokenizer=tokenizer)
|
12 |
+
|
13 |
+
pixel_values = processor(image, return_tensors="pt").pixel_values
|
14 |
+
generated_ids = model.generate(pixel_values)
|
15 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
16 |
+
|
17 |
+
return generated_text
|
18 |
+
|
19 |
+
demo = gr.Interface(fn=OCR, inputs=gr.Image(show_label=False, type="pil"),outputs=gr.Textbox())
|
20 |
+
demo.launch(debug=True)
|