UniquePratham commited on
Commit
acb8143
1 Parent(s): 7d9d109

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -22
app.py CHANGED
@@ -157,6 +157,12 @@ col1, col2 = st.columns([2, 1])
157
  cleaned_text = ""
158
  polished_text = ""
159
 
 
 
 
 
 
 
160
  # Display image preview
161
  if uploaded_file:
162
  image = Image.open(uploaded_file)
@@ -178,12 +184,6 @@ if uploaded_file:
178
  result_path = os.path.join(
179
  results_dir, "temp_file_result.json" if clipboard_use else f"{uploaded_file.name}_result.json")
180
 
181
- # Display extracted text
182
- if 'cleaned_text' not in st.session_state:
183
- st.session_state.cleaned_text = ""
184
- if 'polished_text' not in st.session_state:
185
- st.session_state.polished_text = ""
186
-
187
  # Handle predictions
188
  if predict_button:
189
  if os.path.exists(result_path):
@@ -226,19 +226,21 @@ if uploaded_file:
226
  st.session_state.cleaned_text = cleaned_text
227
  st.session_state.polished_text = polished_text
228
 
229
- # Display extracted text
230
- st.subheader("Extracted Text (Cleaned & Polished)")
231
- st.markdown(st.session_state.cleaned_text, unsafe_allow_html=True)
232
- st.markdown(st.session_state.polished_text, unsafe_allow_html=True)
233
- # Input search term with real-time update on key press
234
- search_query = st_keyup("Search in extracted text:")
235
-
236
- if search_query:
237
- index = st.session_state.cleaned_text.find(search_query)
238
- start = index
239
- len = len(search_query)
240
- end = index + len
241
- if index != -1:
242
- highlight_text(st.session_state.cleaned_text, start, end)
243
- else:
244
- st.write("No Search Found.")
 
 
 
157
  cleaned_text = ""
158
  polished_text = ""
159
 
160
+ # Display extracted text
161
+ if 'cleaned_text' not in st.session_state:
162
+ st.session_state.cleaned_text = ""
163
+ if 'polished_text' not in st.session_state:
164
+ st.session_state.polished_text = ""
165
+
166
  # Display image preview
167
  if uploaded_file:
168
  image = Image.open(uploaded_file)
 
184
  result_path = os.path.join(
185
  results_dir, "temp_file_result.json" if clipboard_use else f"{uploaded_file.name}_result.json")
186
 
 
 
 
 
 
 
187
  # Handle predictions
188
  if predict_button:
189
  if os.path.exists(result_path):
 
226
  st.session_state.cleaned_text = cleaned_text
227
  st.session_state.polished_text = polished_text
228
 
229
+ # Display extracted text
230
+ st.subheader("Extracted Text (Cleaned & Polished)")
231
+ if st.session_state.cleaned_text:
232
+ st.markdown(st.session_state.cleaned_text, unsafe_allow_html=True)
233
+ if st.session_state.polished_text:
234
+ st.markdown(st.session_state.polished_text, unsafe_allow_html=True)
235
+ # Input search term with real-time update on key press
236
+ search_query = st_keyup("Search in extracted text:")
237
+
238
+ if search_query:
239
+ index = st.session_state.cleaned_text.find(search_query)
240
+ start = index
241
+ len = len(search_query)
242
+ end = index + len
243
+ if index != -1:
244
+ highlight_text(st.session_state.cleaned_text, start, end)
245
+ else:
246
+ st.write("No Search Found.")