amit-scans ajitrajasekharan commited on
Commit
6757d9d
0 Parent(s):

Duplicate from ajitrajasekharan/Image-Text-Detection

Browse files

Co-authored-by: ajit rajasekharan <[email protected]>

Files changed (4) hide show
  1. .gitattributes +27 -0
  2. README.md +13 -0
  3. app.py +62 -0
  4. requirements.txt +4 -0
.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Image Text Detection
3
+ emoji: 👀
4
+ colorFrom: yellow
5
+ colorTo: yellow
6
+ sdk: streamlit
7
+ app_file: app.py
8
+ pinned: false
9
+ license: mit
10
+ duplicated_from: ajitrajasekharan/Image-Text-Detection
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import PIL
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 'disp' not in st.session_state:
14
+ st.session_state['disp'] = st.empty()
15
+ st.session_state['disp'].text("Setting up environment with latest build of easyocr. This will take about a minute ")
16
+ if 'init' not in st.session_state:
17
+ st.session_state['init'] = 1
18
+ os.system('pip install git+git://github.com/jaidedai/easyocr.git')
19
+ os.system('pip install git+https://github.com/huggingface/transformers.git --upgrade')
20
+
21
+
22
+
23
+ init_session_states()
24
+ import easyocr
25
+ from transformers import TrOCRProcessor, VisionEncoderDecoderModel
26
+
27
+ def text_recognition(image):
28
+ processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
29
+ model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
30
+ #processor = TrOCRProcessor.from_pretrained("microsoft/trocr-large-handwritten")
31
+ #model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-large-handwritten")
32
+
33
+ pixel_values = processor(image, return_tensors="pt").pixel_values
34
+ generated_ids = model.generate(pixel_values)
35
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
36
+ st.write(generated_text)
37
+
38
+ def main():
39
+
40
+ st.session_state['disp'].text("Env setup up Complete")
41
+ uploaded_file = st.file_uploader("Choose image file to detect text",type=['jpeg','jpg'])
42
+ if uploaded_file is not None:
43
+ file_details = {"FileName":uploaded_file.name,"FileType":uploaded_file.type,"FileSize":uploaded_file.size}
44
+ st.write(file_details)
45
+ image = load_image(uploaded_file)
46
+ st.image(image,width=500)
47
+ st.write("Detecting text bounding box and Take 1 recognition...")
48
+ reader = easyocr.Reader(['en'],gpu=True)
49
+ bound = reader.readtext(image)
50
+ st.write("Bounding box Detection complete")
51
+ st.write(str(bound))
52
+ st.write("Recognizing text - Take 2....")
53
+ text_recognition(image)
54
+
55
+
56
+
57
+ if __name__ == "__main__":
58
+ main()
59
+
60
+
61
+
62
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ pillow
2
+ sentencepiece
3
+ transformers
4
+ streamlit==1.1.0