Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import streamlit as st
|
|
4 |
import io
|
5 |
|
6 |
from ocr_utils import extract_text
|
7 |
-
|
8 |
|
9 |
# Streamlit app layout
|
10 |
st.title("OCR Text Extraction from Images")
|
@@ -33,21 +33,16 @@ if uploaded_file is not None:
|
|
33 |
highlighted_content = highlight_content(full_text, keyword)
|
34 |
st.subheader("Highlighted Search Results")
|
35 |
|
36 |
-
# CSS styles for highlighting
|
37 |
-
st.markdown('''
|
38 |
-
<style>
|
39 |
-
.highlight {
|
40 |
-
background-color: yellow;
|
41 |
-
color: black;
|
42 |
-
padding: 0.2em;
|
43 |
-
border-radius: 4px;
|
44 |
-
}
|
45 |
-
<style>
|
46 |
-
''', unsafe_allow_html=True)
|
47 |
-
|
48 |
-
# Render the highlighted content with HTML
|
49 |
-
st.markdown(highlighted_content, unsafe_allow_html=True)
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
else:
|
52 |
st.subheader("Highlighted Search Results")
|
53 |
-
st.write("No keyword entered for highlighting.")
|
|
|
4 |
import io
|
5 |
|
6 |
from ocr_utils import extract_text
|
7 |
+
|
8 |
|
9 |
# Streamlit app layout
|
10 |
st.title("OCR Text Extraction from Images")
|
|
|
33 |
highlighted_content = highlight_content(full_text, keyword)
|
34 |
st.subheader("Highlighted Search Results")
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
if keyword:
|
38 |
+
if keyword in full_text:
|
39 |
+
highlighted_text = full_text.replace(
|
40 |
+
keyword, f"<mark style='background-color: yellow; color: black;'>{keyword}</mark>")
|
41 |
+
st.subheader("Highlighted Search Results")
|
42 |
+
st.markdown(highlighted_text, unsafe_allow_html=True)
|
43 |
+
else:
|
44 |
+
st.subheader("Highlighted Search Results")
|
45 |
+
st.write(f"The keyword '{keyword}' was not found in the text.")
|
46 |
else:
|
47 |
st.subheader("Highlighted Search Results")
|
48 |
+
st.write("No keyword entered for highlighting.")
|