Spaces:
Sleeping
Sleeping
File size: 1,326 Bytes
51efabb 5560167 b026165 ef3c0f4 5560167 51efabb 5560167 51efabb 5560167 51efabb 5560167 51efabb 5560167 51efabb 5560167 51efabb 5560167 51efabb 034d0b5 1b2f4fa 034d0b5 0a07888 b026165 c700954 b026165 c028af8 b026165 034d0b5 3e33879 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import streamlit as st
from PIL import Image
from ocr_utils import extract_text
import numpy as np
# Streamlit application title
st.title("OCR and Keyword Search Application")
st.write("Upload an image containing Hindi and English text to extract and search within the text.")
# File uploader for image
uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Open the uploaded image using PIL
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image', use_column_width=True)
# Convert the image to a NumPy array
image_np = np.array(image)
# Perform OCR on the uploaded image using the utility function
full_text = extract_text(image_np)
# Display the extracted text
st.subheader("Extracted Text")
st.write(full_text)
# Text input for keyword search
keyword = st.text_input("Enter Keyword to Search")
# Highlight the keyword in the extracted text
if keyword:
highlighted_text = full_text.replace(
keyword, f"<mark>{keyword}</mark>")
st.subheader("Highlighted Search Results")
st.markdown(highlighted_text, unsafe_allow_html=True)
else:
st.subheader("Highlighted Search Results")
st.write("No keyword entered for highlighting.")
|