cyperts commited on
Commit
5886ed2
·
verified ·
1 Parent(s): eabb41e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import keras_ocr
3
+ import matplotlib.pyplot as plt
4
+ from PIL import Image
5
+ hide_streamlit_style = """
6
+ <style>
7
+ #MainMenu {visibility: hidden;}
8
+ footer {visibility: hidden;}
9
+ .css-1wbqy5l {visibility: hidden;}
10
+ .css-15zrgzn {visibility: hidden;}
11
+ .css-klqnuk {visibility: hidden;}
12
+ .en6cib64 {visibility: hidden;}
13
+ .css-1u4fkce {visibility: hidden;}
14
+ .en6cib62 {visibility: hidden;}
15
+
16
+ .css-19rxjzo, .ef3psqc11 {
17
+ background-color: purple;
18
+ text-color: white;
19
+ }
20
+
21
+ div.stButton > button:first-child {
22
+ background-color: darkgreen;
23
+ text-weight: bold;
24
+ }
25
+ </style>
26
+ """
27
+ st.markdown("<h1 style='text-align:center;'> Image Text Recognition</h1>", unsafe_allow_html=True)
28
+ st.markdown("<h4 style='text-align:center;'> By Cyperts</h4>", unsafe_allow_html=True)
29
+ st.markdown("---")
30
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
31
+
32
+ placeholder=st.empty()
33
+ col1,col2=placeholder.columns(2)
34
+ col1.image("example.png", width=250)
35
+ col2.markdown("<p style='text-align:left;'> This is an example result</p>", unsafe_allow_html=True)
36
+
37
+ # Read images from folder path to image object
38
+ st.markdown("<h2>Upload an Image with Text</h2>",unsafe_allow_html=True)
39
+ uploaded_img= st.file_uploader("Browse File", type=['jpeg','jpg','png'],accept_multiple_files=False)
40
+ #container2=st.empty()
41
+
42
+ def on_click():
43
+ if uploaded_img is not None:
44
+ pipeline = keras_ocr.pipeline.Pipeline()
45
+ print(uploaded_img.name)
46
+ images = [
47
+ keras_ocr.tools.read(img) for img in [uploaded_img
48
+ ]]
49
+ # generate text predictions from the images
50
+ prediction_groups = pipeline.recognize(images)
51
+ # plot the text predictions
52
+ fig, axs = plt.subplots(nrows=len(images), figsize=(10, 20))
53
+ #for ax, image, predictions in zip(axs, images, prediction_groups):
54
+ #keras_ocr.tools.drawAnnotations(image=images[0],predictions=prediction_groups[0], ax=axs)
55
+ keras_ocr.tools.drawAnnotations(image=images[0], predictions=prediction_groups[0], ax=axs )
56
+
57
+ columnbelow[0].pyplot(fig)
58
+ print(images)
59
+
60
+ if uploaded_img is not None:
61
+ btn=st.button("Recognize Text", on_click=on_click)
62
+
63
+ belowrecognize=st.empty()
64
+ columnbelow=belowrecognize.columns(1) #Returns list
65
+
66
+
67
+
68
+
69
+
70
+