Shabdobhedi commited on
Commit
55c75e6
·
verified ·
1 Parent(s): cd3b7ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -39
app.py CHANGED
@@ -1,39 +1,43 @@
1
- import streamlit as st
2
- from PIL import Image
3
- from ocr_utils import extract_text
4
-
5
- import numpy as np
6
- # Streamlit application title
7
- st.title("OCR and Keyword Search Application")
8
- st.write("Upload an image containing Hindi and English text to extract and search within the text.")
9
-
10
- # File uploader for image
11
- uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
12
-
13
- if uploaded_file is not None:
14
- # Open the uploaded image using PIL
15
- image = Image.open(uploaded_file)
16
- st.image(image, caption='Uploaded Image', use_column_width=True)
17
-
18
- # Convert the image to a NumPy array
19
- image_np = np.array(image)
20
-
21
- # Perform OCR on the uploaded image using the utility function
22
- full_text = extract_text(image_np)
23
-
24
- # Display the extracted text
25
- st.subheader("Extracted Text")
26
- st.write(full_text)
27
-
28
- # Text input for keyword search
29
- keyword = st.text_input("Enter Keyword to Search")
30
-
31
- # Highlight the keyword in the extracted text
32
- if keyword:
33
- highlighted_text = full_text.replace(
34
- keyword, f"<mark style='background-color: yellow; color: black;'>{keyword}</mark>")
35
- st.subheader("Highlighted Search Results")
36
- st.markdown(highlighted_text, unsafe_allow_html=True)
37
- else:
38
- st.subheader("Highlighted Search Results")
39
- st.write("No keyword entered for highlighting.")
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ from ocr_utils import extract_text
4
+
5
+ import numpy as np
6
+ # Streamlit application title
7
+ st.title("OCR and Keyword Search Application")
8
+ st.write("Upload an image containing Hindi and English text to extract and search within the text.")
9
+
10
+ # File uploader for image
11
+ uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
12
+
13
+ if uploaded_file is not None:
14
+ # Open the uploaded image using PIL
15
+ image = Image.open(uploaded_file)
16
+ st.image(image, caption='Uploaded Image', use_column_width=True)
17
+
18
+ # Convert the image to a NumPy array
19
+ image_np = np.array(image)
20
+
21
+ # Perform OCR on the uploaded image using the utility function
22
+ full_text = extract_text(image_np)
23
+
24
+ # Display the extracted text
25
+ st.subheader("Extracted Text")
26
+ st.write(full_text)
27
+
28
+ # Text input for keyword search
29
+ keyword = st.text_input("Enter Keyword to Search")
30
+
31
+ #Highlight the keyword in the extracted text
32
+ if keyword:
33
+ if keyword in full_text:
34
+ highlighted_text = full_text.replace(
35
+ keyword, f"<mark style='background-color: yellow; color: black;'>{keyword}</mark>")
36
+ st.subheader("Highlighted Search Results")
37
+ st.markdown(highlighted_text, unsafe_allow_html=True)
38
+ else:
39
+ st.subheader("Highlighted Search Results")
40
+ st.write(f"The keyword '{keyword}' was not found in the text.")
41
+ else:
42
+ st.subheader("Highlighted Search Results")
43
+ st.write("No keyword entered for highlighting.")