Spaces:
Running
Running
UniquePratham
commited on
Commit
β’
55c903d
1
Parent(s):
1477de6
Update app.py
Browse files
app.py
CHANGED
@@ -87,12 +87,15 @@ def extract_text_qwen(image_file, model, processor):
|
|
87 |
|
88 |
# Highlight keyword search
|
89 |
def highlight_text(text, search_term):
|
90 |
-
if not search_term:
|
91 |
return text
|
|
|
92 |
pattern = re.compile(re.escape(search_term), re.IGNORECASE)
|
|
|
93 |
return pattern.sub(lambda m: f'<span style="background-color: yellow;">{m.group()}</span>', text)
|
94 |
|
95 |
# Title and UI
|
|
|
96 |
st.title("OCR Application - Multimodel Support")
|
97 |
st.write("Upload an image for OCR using various models, with support for English, Hindi, and Hinglish.")
|
98 |
|
@@ -161,11 +164,16 @@ if predict_button and uploaded_file:
|
|
161 |
st.subheader("Extracted Text (Cleaned & Polished)")
|
162 |
st.markdown(polished_text, unsafe_allow_html=True)
|
163 |
|
|
|
164 |
search_query = st.text_input("Search in extracted text:", key="search_query", placeholder="Type to search...")
|
|
|
165 |
if search_query:
|
|
|
166 |
highlighted_text = highlight_text(polished_text, search_query)
|
167 |
st.markdown("### Highlighted Search Results:")
|
|
|
168 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|
169 |
else:
|
|
|
170 |
st.markdown("### Extracted Text:")
|
171 |
-
st.markdown(polished_text
|
|
|
87 |
|
88 |
# Highlight keyword search
|
89 |
def highlight_text(text, search_term):
|
90 |
+
if not search_term: # If no search term is provided, return the original text
|
91 |
return text
|
92 |
+
# Use a regular expression to search for the term, case insensitive
|
93 |
pattern = re.compile(re.escape(search_term), re.IGNORECASE)
|
94 |
+
# Highlight matched terms with yellow background
|
95 |
return pattern.sub(lambda m: f'<span style="background-color: yellow;">{m.group()}</span>', text)
|
96 |
|
97 |
# Title and UI
|
98 |
+
st.title("DualTextOCRFusion - π")
|
99 |
st.title("OCR Application - Multimodel Support")
|
100 |
st.write("Upload an image for OCR using various models, with support for English, Hindi, and Hinglish.")
|
101 |
|
|
|
164 |
st.subheader("Extracted Text (Cleaned & Polished)")
|
165 |
st.markdown(polished_text, unsafe_allow_html=True)
|
166 |
|
167 |
+
# Input box for real-time search
|
168 |
search_query = st.text_input("Search in extracted text:", key="search_query", placeholder="Type to search...")
|
169 |
+
# Update results dynamically based on the search term
|
170 |
if search_query:
|
171 |
+
# Highlight the search term in the text
|
172 |
highlighted_text = highlight_text(polished_text, search_query)
|
173 |
st.markdown("### Highlighted Search Results:")
|
174 |
+
# Render the highlighted text, allowing HTML rendering for the highlight
|
175 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|
176 |
else:
|
177 |
+
# If no search term is provided, display the original text
|
178 |
st.markdown("### Extracted Text:")
|
179 |
+
st.markdown(polished_text)
|