File size: 1,549 Bytes
fe7691a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
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

# Streamlit app layout
st.title("OCR Text Extraction from Images")

# File uploader widget
uploaded_file = st.file_uploader(
    "Upload an Image", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    # Open and display the uploaded image
    image = Image.open(uploaded_file)
    st.image(image, caption='Uploaded Image', use_column_width=True)

    # Extract text from the image
    full_text = extract_text(image)

    # 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")
    # Display highlighted content if a keyword is entered
    if keyword:

        highlighted_content = highlight_content(full_text, keyword)
        st.subheader("Highlighted Search Results")

      # CSS styles for highlighting
        st.markdown('''

        <style>

        .highlight {

            background-color: yellow;

            color: black;

            padding: 0.2em;

            border-radius: 4px;

        }

        <style>

        ''', unsafe_allow_html=True)

        # Render the highlighted content with HTML
        st.markdown(highlighted_content, unsafe_allow_html=True)

    else:
        st.subheader("Highlighted Search Results")
        st.write("No keyword entered for highlighting.")