Mohuu0601 commited on
Commit
3487445
·
verified ·
1 Parent(s): 5778549

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 - hosted on 🦄 Spaces")
11
+
12
+ st.markdown("")
13
+
14
+ # Image uploader
15
+ image = st.file_uploader(label="Upload your image here", type=['png', 'jpg', 'jpeg'])
16
+
17
+ @st.cache
18
+ def load_model():
19
+ reader = ocr.Reader(['en'], model_storage_directory='.')
20
+ return reader
21
+
22
+ reader = load_model() # Load model
23
+
24
+ if image is not None:
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
+ result = reader.readtext(np.array(input_image))
30
+
31
+ result_text = [] # Empty list for results
32
+
33
+ for text in result:
34
+ result_text.append(text[1])
35
+
36
+ st.write(result_text)
37
+ st.success("Here you go!")
38
+ st.balloons()
39
+ else:
40
+ st.write("Upload an Image")
41
+
42
+ st.caption("Made with ❤ by @littlecoder")