Spaces:
Runtime error
Runtime error
Commit ·
8f25cfa
1
Parent(s): 66cafe3
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import pandas as pdimport numpy as npimport PILfrom PIL import Imageimport streamlit as stimport torchimport easyocrfrom matplotlib import pyplot as plt
# main titlest.title("Get text from image with EasyOCR")
# subtitlest.markdown("## EasyOCRR with Streamlit")
# upload image fileimage = st.file_uploader(label = "Upload your image", type=['png', 'jpg', 'jpeg'])
#read the csv file and display the dataframeif file is not None: image = Image.open(file) # read image with PIL library st.image(image) #display
# it will only detect the English and Turkish part of the image as text reader = easyocr.Reader(['tr','en'], gpu=False) result = reader.readtext(np.array(image)) # turn image to numpy array
# collect the results in dictionary: textdic_easyocr = {} for idx in range(len(result)): pred_coor = result[idx][0] pred_text = result[idx][1] pred_confidence = result[idx][2] textdic_easyocr[pred_text] = {} textdic_easyocr[pred_text]['pred_confidence'] = pred_confidence df = pd.DataFrame.from_dict(textdic_easyocr).T st.table(df)
ax1.plot(agg_df.year, agg_df.rating) st.pyplot(fig1) for res in result: top_left = tuple(res[0][0]) # top left coordinates as tuple bottom_right = tuple(res[0][2]) # bottom right coordinates as tuple # draw rectangle on image, 2 is thickness cv2.rectangle(image, top_left, bottom_right, (0, 255, 0), 2) # write recognized text on image (top_left) minus 10 pixel on y cv2.putText(image, res[1], (top_left[0], top_left[1]-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2) fig1, ax1 = plt.subplots() plt.imshow(image) plt.show() else: st.write("Upload your image")app.pyAdded+57