|
import google.generativeai as genai
|
|
from PIL import Image
|
|
import streamlit as st
|
|
import io
|
|
|
|
from ocr_utils import extract_text
|
|
from ocr_utils import highlight_content
|
|
|
|
|
|
st.title("OCR Text Extraction from Images")
|
|
|
|
|
|
uploaded_file = st.file_uploader(
|
|
"Upload an Image", type=["jpg", "jpeg", "png"])
|
|
|
|
if uploaded_file is not None:
|
|
|
|
image = Image.open(uploaded_file)
|
|
st.image(image, caption='Uploaded Image', use_column_width=True)
|
|
|
|
|
|
full_text = extract_text(image)
|
|
|
|
|
|
st.subheader("Extracted Text")
|
|
st.write(full_text)
|
|
|
|
|
|
keyword = st.text_input("Enter Keyword to Search")
|
|
|
|
if keyword:
|
|
|
|
highlighted_content = highlight_content(full_text, keyword)
|
|
st.subheader("Highlighted Search Results")
|
|
|
|
|
|
st.markdown('''
|
|
<style>
|
|
.highlight {
|
|
background-color: yellow;
|
|
color: black;
|
|
padding: 0.2em;
|
|
border-radius: 4px;
|
|
}
|
|
<style>
|
|
''', unsafe_allow_html=True)
|
|
|
|
|
|
st.markdown(highlighted_content, unsafe_allow_html=True)
|
|
|
|
else:
|
|
st.subheader("Highlighted Search Results")
|
|
st.write("No keyword entered for highlighting.")
|
|
|