ajitrajasekharan's picture
Update app.py
18f20c2
raw
history blame
1.04 kB
import PIL
from PIL import ImageDraw
from PIL import Image
import streamlit as st
import sentencepiece
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
def load_image(image_file):
img = PIL.Image.open(image_file)
return img
uploaded_file = st.file_uploader("Upload Files",type=['png','jpeg','jpg'])
if uploaded_file is not None:
file_details = {"FileName":uploaded_file.name,"FileType":uploaded_file.type,"FileSize":uploaded_file.size}
st.write(file_details)
image = load_image(uploaded_file)
st.image(image,width=250)
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-large-handwritten")
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-large-handwritten")
image = image.convert("RGB")
pixel_values = processor(image, return_tensors="pt").pixel_values
generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
st.write(generated_text)