Spaces:
Sleeping
Sleeping
Update app.py
Browse filesfixed image input type
app.py
CHANGED
@@ -4,19 +4,17 @@ import gradio as gr
|
|
4 |
from PIL import Image
|
5 |
|
6 |
def OCR(image):
|
7 |
-
# Load the image
|
8 |
-
img = Image.open(image)
|
9 |
|
10 |
model = VisionEncoderDecoderModel.from_pretrained("kavg/TrOCR-SIN")
|
11 |
tokenizer = AutoTokenizer.from_pretrained('NLPC-UOM/SinBERT-large')
|
12 |
feature_extractor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
|
13 |
processor = TrOCRProcessor(image_processor=feature_extractor, tokenizer=tokenizer)
|
14 |
|
15 |
-
pixel_values = processor(
|
16 |
generated_ids = model.generate(pixel_values)
|
17 |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
18 |
|
19 |
return generated_text
|
20 |
|
21 |
-
demo = gr.Interface(fn=OCR, inputs=gr.Image(),outputs=gr.Textbox())
|
22 |
demo.launch(debug=True)
|
|
|
4 |
from PIL import Image
|
5 |
|
6 |
def OCR(image):
|
|
|
|
|
7 |
|
8 |
model = VisionEncoderDecoderModel.from_pretrained("kavg/TrOCR-SIN")
|
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(label="Select an image with Sinhala textline", type="pil"),outputs=gr.Textbox())
|
20 |
demo.launch(debug=True)
|