iohanngrig commited on
Commit
a67a7d0
·
verified ·
1 Parent(s): 517ab0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -21
app.py CHANGED
@@ -4,44 +4,31 @@ 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
  st.markdown("Link to the app - [image-to-text-app on 🤗 Spaces](https://huggingface.co/spaces/Amrrs/image-to-text-app)")
13
 
14
  #image uploader
15
- image = st.file_uploader(label = "Upload your image here",type=['png','jpg','jpeg'])
16
 
17
 
18
- @st.cache
19
  def load_model():
20
  reader = ocr.Reader(['en'],model_storage_directory='.')
21
  return reader
22
 
23
- reader = load_model() #load model
24
 
25
  if image is not None:
26
-
27
  input_image = Image.open(image) #read image
28
- st.image(input_image) #display image
29
-
30
- with st.spinner("🤖 AI is at Work! "):
31
-
32
-
33
  result = reader.readtext(np.array(input_image))
34
-
35
- result_text = [] #empty list for results
36
-
37
-
38
  for text in result:
39
  result_text.append(text[1])
40
-
41
  st.write(result_text)
42
- #st.success("Here you go!")
43
  st.balloons()
44
  else:
45
- st.write("Upload an Image")
46
-
47
- st.caption("Made with ❤️ by @1littlecoder. Credits to 🤗 Spaces for Hosting this ")
 
4
  import numpy as np #Image Processing
5
 
6
  #title
7
+ st.title("Image to Text Toy Application")
8
 
9
  #subtitle
 
 
10
  st.markdown("Link to the app - [image-to-text-app on 🤗 Spaces](https://huggingface.co/spaces/Amrrs/image-to-text-app)")
11
 
12
  #image uploader
13
+ image = st.file_uploader(label = "Upload your image here", type=['png','jpg','jpeg'])
14
 
15
 
16
+ @st.cache_data
17
  def load_model():
18
  reader = ocr.Reader(['en'],model_storage_directory='.')
19
  return reader
20
 
21
+ reader = load_model()
22
 
23
  if image is not None:
 
24
  input_image = Image.open(image) #read image
25
+ st.image(input_image)
26
+ with st.spinner("AI is at Work!"):
 
 
 
27
  result = reader.readtext(np.array(input_image))
28
+ result_text = []
 
 
 
29
  for text in result:
30
  result_text.append(text[1])
 
31
  st.write(result_text)
 
32
  st.balloons()
33
  else:
34
+ st.write("Upload an Image")