import PIL from PIL import ImageDraw from PIL import Image import streamlit as st import os def load_image(image_file): img = PIL.Image.open(image_file) return img def init_session_states(): if 'disp' not in st.session_state: st.session_state['disp'] = st.empty() st.session_state['disp'].text("Setting up environment. This will take some time...") if 'init' not in st.session_state: st.session_state['init'] = 1 os.system('pip install git+git://github.com/jaidedai/easyocr.git') os.system('pip install git+https://github.com/huggingface/transformers.git --upgrade') init_session_states() import easyocr from transformers import TrOCRProcessor, VisionEncoderDecoderModel def main(): st.session_state['disp'].text("Env setup up Complete") uploaded_file = st.file_uploader("Choose image file to detect text",type=['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=500) #st.session_state['disp'].text("Detecting text....") st.write("Detecting text...") reader = easyocr.Reader(['en'],gpu=True) bound = reader.readtext(image) st.write("Detection complete") st.write(str(bound)) #st.session_state['disp'].text("Detection complete") if __name__ == "__main__": main()