import streamlit as st import keras_ocr import matplotlib.pyplot as plt from PIL import Image hide_streamlit_style = """ """ st.markdown("

Image Text Recognition

", unsafe_allow_html=True) st.markdown("

By Alok

", unsafe_allow_html=True) st.markdown("---") st.markdown(hide_streamlit_style, unsafe_allow_html=True) placeholder=st.empty() col1,col2=placeholder.columns(2) col1.image("https://i.ibb.co/HdRnpzQ/example1.png", width=250) col2.markdown("

This is an example result

", unsafe_allow_html=True) # Read images from folder path to image object st.markdown("

Upload an Image with Text

",unsafe_allow_html=True) uploaded_img= st.file_uploader("Browse File", type=['jpeg','jpg','png'],accept_multiple_files=False) #container2=st.empty() def on_click(): if uploaded_img is not None: pipeline = keras_ocr.pipeline.Pipeline() print(uploaded_img.name) images = [ keras_ocr.tools.read(img) for img in [uploaded_img ]] # generate text predictions from the images prediction_groups = pipeline.recognize(images) # plot the text predictions fig, axs = plt.subplots(nrows=len(images), figsize=(10, 20)) #for ax, image, predictions in zip(axs, images, prediction_groups): #keras_ocr.tools.drawAnnotations(image=images[0],predictions=prediction_groups[0], ax=axs) keras_ocr.tools.drawAnnotations(image=images[0], predictions=prediction_groups[0], ax=axs ) columnbelow[0].pyplot(fig) print(images) if uploaded_img is not None: btn=st.button("Recognize Text", on_click=on_click) belowrecognize=st.empty() columnbelow=belowrecognize.columns(1) #Returns list