Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,13 +18,13 @@ def rectangle(image, result):
|
|
| 18 |
|
| 19 |
|
| 20 |
# main title
|
| 21 |
-
st.title("
|
| 22 |
|
| 23 |
# subtitle
|
| 24 |
-
st.markdown("##
|
| 25 |
|
| 26 |
# upload image file
|
| 27 |
-
file = st.file_uploader(label = "Upload
|
| 28 |
|
| 29 |
#read the csv file and display the dataframe
|
| 30 |
if file is not None:
|
|
@@ -32,23 +32,9 @@ if file is not None:
|
|
| 32 |
st.image(image) #display
|
| 33 |
|
| 34 |
# it will only detect the English and Turkish part of the image as text
|
| 35 |
-
reader = easyocr.Reader(['en'
|
| 36 |
result = reader.readtext(np.array(image)) # turn image to numpy array
|
| 37 |
|
| 38 |
-
# Add a placeholder
|
| 39 |
-
# latest_iteration = st.empty()
|
| 40 |
-
# bar = st.progress(0)
|
| 41 |
-
|
| 42 |
-
# for i in range(100):
|
| 43 |
-
# Update the progress bar with each iteration.
|
| 44 |
-
# latest_iteration.text(f'Iteration {i+1}')
|
| 45 |
-
# bar.progress(i + 1)
|
| 46 |
-
# time.sleep(0.1)
|
| 47 |
-
|
| 48 |
-
# print all predicted text:
|
| 49 |
-
for idx in range(len(result)):
|
| 50 |
-
pred_text = result[idx][1]
|
| 51 |
-
st.write(pred_text)
|
| 52 |
|
| 53 |
# collect the results in the dictionary:
|
| 54 |
textdic_easyocr = {}
|
|
@@ -56,8 +42,9 @@ if file is not None:
|
|
| 56 |
pred_coor = result[idx][0]
|
| 57 |
pred_text = result[idx][1]
|
| 58 |
pred_confidence = result[idx][2]
|
| 59 |
-
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
# create a data frame which shows the predicted text and prediction confidence
|
| 63 |
df = pd.DataFrame.from_dict(textdic_easyocr).T
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
# main title
|
| 21 |
+
st.title("Recognize text and locations from flowchart")
|
| 22 |
|
| 23 |
# subtitle
|
| 24 |
+
st.markdown("## FlowchartOCR")
|
| 25 |
|
| 26 |
# upload image file
|
| 27 |
+
file = st.file_uploader(label = "Upload Image", type=['png', 'jpg', 'jpeg'])
|
| 28 |
|
| 29 |
#read the csv file and display the dataframe
|
| 30 |
if file is not None:
|
|
|
|
| 32 |
st.image(image) #display
|
| 33 |
|
| 34 |
# it will only detect the English and Turkish part of the image as text
|
| 35 |
+
reader = easyocr.Reader(['en'], gpu=False)
|
| 36 |
result = reader.readtext(np.array(image)) # turn image to numpy array
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# collect the results in the dictionary:
|
| 40 |
textdic_easyocr = {}
|
|
|
|
| 42 |
pred_coor = result[idx][0]
|
| 43 |
pred_text = result[idx][1]
|
| 44 |
pred_confidence = result[idx][2]
|
| 45 |
+
if(pred_confidence>0.6):
|
| 46 |
+
textdic_easyocr[pred_text] = {}
|
| 47 |
+
textdic_easyocr[pred_text]['pred_confidence'] = pred_confidence
|
| 48 |
|
| 49 |
# create a data frame which shows the predicted text and prediction confidence
|
| 50 |
df = pd.DataFrame.from_dict(textdic_easyocr).T
|