itsanurag commited on
Commit
f08eaaf
1 Parent(s): eacd63a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import easyocr as ocr #OCR
2
+ import streamlit as st #Web App
3
+ from PIL import Image #Image Processing
4
+ import numpy as np #Image Processing
5
+
6
+ #title
7
+ st.title("Easy OCR - Extract Text from Images")
8
+
9
+ #subtitle
10
+ st.markdown("## Optical Character Recognition - Using `easyocr`, `streamlit` - hosted on 🤗 Spaces")
11
+
12
+ #image uploader
13
+ image = st.file_uploader(label = "Upload your image here",type=['png','jpg','jpeg'])
14
+
15
+
16
+ @st.cache
17
+ def load_model():
18
+ reader = ocr.Reader(['en'],model_storage_directory='.')
19
+ return reader
20
+
21
+ reader = load_model() #load model
22
+
23
+ if image is not None:
24
+
25
+ input_image = Image.open(image) #read image
26
+ st.image(input_image) #display image
27
+
28
+ with st.spinner("🤖 AI is at Work! "):
29
+
30
+
31
+ result = reader.readtext(np.array(input_image))
32
+
33
+ result_text = [] #empty list for results
34
+
35
+
36
+ for text in result:
37
+ result_text.append(text[1])
38
+
39
+ st.write(result_text)
40
+ #st.success("Here you go!")
41
+ st.balloons()
42
+ else:
43
+ st.write("Upload an Image")
44
+
45
+ st.caption("Made with ❤️ by @itsANURAG. Credits to 🤗 Spaces for Hosting this ")