Update app.py
Browse files
app.py
CHANGED
@@ -121,22 +121,24 @@ if uploaded_file is not None:
|
|
121 |
|
122 |
# Step 9: Implement a search functionality on already extracted text
|
123 |
if st.session_state.extracted_text:
|
124 |
-
with st.form(key='
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
if
|
129 |
-
#
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
for
|
136 |
-
|
137 |
-
|
|
|
|
|
138 |
|
139 |
st.subheader("Search Results:")
|
140 |
-
if result ==
|
141 |
st.markdown('Not forund')
|
142 |
st.markdown(result)
|
|
|
121 |
|
122 |
# Step 9: Implement a search functionality on already extracted text
|
123 |
if st.session_state.extracted_text:
|
124 |
+
with st.form(key='text_search_form'):
|
125 |
+
search_input = st.text_input("Enter a keyword to search within the extracted text:")
|
126 |
+
search_action = st.form_submit_button("Search")
|
127 |
+
|
128 |
+
if search_action and search_input:
|
129 |
+
# Split the extracted text into lines for searching
|
130 |
+
full_text = st.session_state.exttracted_text
|
131 |
+
lines = full_text.split('\n')
|
132 |
+
|
133 |
+
results = []
|
134 |
+
# Search for keyword in each line and collect lines that contain the keyword
|
135 |
+
for line in lines:
|
136 |
+
if re.search(re.escape(search_input), line, re.IGNORECASE):
|
137 |
+
# Highlight keyword in the line
|
138 |
+
highlighted_line = re.sub(f"({re.escape(search_input)})", r"*\1*", line, flags=re.IGNORECASE)
|
139 |
+
results.append(highlighted_line)
|
140 |
|
141 |
st.subheader("Search Results:")
|
142 |
+
if result == []:
|
143 |
st.markdown('Not forund')
|
144 |
st.markdown(result)
|