Kethan20 commited on
Commit
48af6c5
1 Parent(s): 2a1e7f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -35
app.py CHANGED
@@ -1,36 +1,36 @@
1
- from transformers import AutoModel, AutoTokenizer
2
- import streamlit as st
3
- from PIL import Image
4
- import tempfile
5
-
6
-
7
-
8
- def perform_ocr(image):
9
- tokenizer = AutoTokenizer.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True)
10
- model = AutoModel.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True, low_cpu_mem_usage=True, use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
11
- model = model.eval()
12
- res = model.chat(tokenizer, image, ocr_type='ocr')
13
- return res
14
-
15
-
16
- # Title and instructions
17
- st.title(' OCR and Document Search Web Application Prototype')
18
- st.write('Upload an image and extract text in Hindi and English. You can also search for keywords within the extracted text.')
19
-
20
- # Upload the image
21
- uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "png", "jpeg"])
22
-
23
- # If an image is uploaded
24
- if uploaded_file is not None:
25
- image = Image.open(uploaded_file)
26
- st.image(image, caption='Uploaded Image.', use_column_width=True)
27
-
28
- with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
29
- temp_file.write(uploaded_file.getbuffer())
30
- temp_file_path = temp_file.name
31
-
32
- # Perform OCR on the uploaded image
33
- st.write("Extracting text...")
34
- extracted_text = perform_ocr(temp_file_path)
35
- st.write("Extracted Text:")
36
  st.text_area("OCR Output", extracted_text, height=200)
 
1
+ from transformers import AutoModel, AutoTokenizer
2
+ import streamlit as st
3
+ from PIL import Image
4
+ import tempfile
5
+
6
+
7
+
8
+ def perform_ocr(image):
9
+ tokenizer = AutoTokenizer.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True)
10
+ model = AutoModel.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True, low_cpu_mem_usage=True, use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
11
+ model = model.eval()
12
+ res = model.chat(tokenizer, image, ocr_type='ocr')
13
+ return res
14
+
15
+
16
+ # Title and instructions
17
+ st.title(' OCR and Document Search Web Application Prototype')
18
+ st.write('Upload an image and extract text in Hindi and English. You can also search for keywords within the extracted text.')
19
+
20
+ # Upload the image
21
+ uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "png", "jpeg"])
22
+
23
+ # If an image is uploaded
24
+ if uploaded_file is not None:
25
+ image = Image.open(uploaded_file)
26
+ st.image(image, caption='Uploaded Image.', use_column_width=True)
27
+
28
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
29
+ temp_file.write(uploaded_file.getbuffer())
30
+ temp_file_path = temp_file.name
31
+
32
+ # Perform OCR on the uploaded image
33
+ st.write("Extracting text...")
34
+ extracted_text = perform_ocr(temp_file_path)
35
+ st.write("Extracted Text:")
36
  st.text_area("OCR Output", extracted_text, height=200)