ajitrajasekharan commited on
Commit
fcc8fb8
·
1 Parent(s): 837c3d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -16
app.py CHANGED
@@ -2,32 +2,42 @@ import PIL
2
  from PIL import ImageDraw
3
  from PIL import Image
4
  import streamlit as st
5
-
6
-
7
- display_area = st.empty()
8
- display_area.text("Setting up environment. This will take some time...")
9
  import os
10
- os.system('pip install git+git://github.com/jaidedai/easyocr.git')
11
- import easyocr
12
- display_area.text("Env setup up Complete")
13
 
14
  def load_image(image_file):
15
  img = PIL.Image.open(image_file)
16
  return img
17
 
 
 
 
 
 
 
 
18
 
19
 
20
- uploaded_file = st.file_uploader("Choose image file to detect text",type=['png','jpeg','jpg'])
21
- if uploaded_file is not None:
22
- file_details = {"FileName":uploaded_file.name,"FileType":uploaded_file.type,"FileSize":uploaded_file.size}
23
- st.write(file_details)
24
- image = load_image(uploaded_file)
25
- st.image(image,width=250)
26
- reader = easyocr.Reader(['en'],gpu=True)
27
- bound = reader.readtext(image)
28
- st.write(str(bound))
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
 
 
31
 
32
 
33
 
 
2
  from PIL import ImageDraw
3
  from PIL import Image
4
  import streamlit as st
 
 
 
 
5
  import os
6
+
 
 
7
 
8
  def load_image(image_file):
9
  img = PIL.Image.open(image_file)
10
  return img
11
 
12
+ def init_session_states():
13
+ if 'init' not in st.session_state:
14
+ st.session_state['init'] = 1
15
+ os.system('pip install git+git://github.com/jaidedai/easyocr.git')
16
+ if 'disp' not in st.session_state:
17
+ st.session_state['disp'] = st.empty()
18
+ st.session_state['disp'].text("Setting up environment. This will take some time...")
19
 
20
 
 
 
 
 
 
 
 
 
 
21
 
22
+ init_session_states()
23
+ import easyocr
24
+
25
+ def main():
26
+ st.session_state['disp'].text.text("Env setup up Complete")
27
+ uploaded_file = st.file_uploader("Choose image file to detect text",type=['jpeg','jpg'])
28
+ if uploaded_file is not None:
29
+ file_details = {"FileName":uploaded_file.name,"FileType":uploaded_file.type,"FileSize":uploaded_file.size}
30
+ st.write(file_details)
31
+ image = load_image(uploaded_file)
32
+ st.image(image,width=250)
33
+ reader = easyocr.Reader(['en'],gpu=True)
34
+ bound = reader.readtext(image)
35
+ st.write(str(bound))
36
+
37
+
38
 
39
+ if __name__ == "__main__":
40
+ main()
41
 
42
 
43