Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +7 -11
src/streamlit_app.py
CHANGED
|
@@ -264,7 +264,7 @@ storage_field_name = SINGLE_FIELDS[0]
|
|
| 264 |
base_field_for_color = SINGLE_FIELDS[0]
|
| 265 |
|
| 266 |
with col2:
|
| 267 |
-
# ========== FIELD SELECTION (
|
| 268 |
st.markdown("#### π― Field Selection")
|
| 269 |
|
| 270 |
def add_line_item():
|
|
@@ -293,7 +293,7 @@ with col2:
|
|
| 293 |
else:
|
| 294 |
num_items = st.session_state.num_line_items[selected_name]
|
| 295 |
|
| 296 |
-
#
|
| 297 |
line_col1, add_col, rem_col = st.columns([2, 1, 1])
|
| 298 |
with line_col1:
|
| 299 |
line_item_options = [f"Line {i+1}" for i in range(num_items)]
|
|
@@ -318,7 +318,7 @@ with col2:
|
|
| 318 |
field_color = FIELD_COLORS.get(base_field_for_color or display_field_name, "#FF0000")
|
| 319 |
st.markdown(f"**Current:** <span style='color:{field_color}'>β</span> {display_field_name}", unsafe_allow_html=True)
|
| 320 |
|
| 321 |
-
# ========== ZOOM CONTROLS (
|
| 322 |
st.markdown("#### π Zoom")
|
| 323 |
|
| 324 |
current_zoom = st.session_state.zoom_values[selected_name]
|
|
@@ -374,13 +374,10 @@ with col2:
|
|
| 374 |
|
| 375 |
current_rect_orig = st.session_state.field_rects_orig[selected_name].get(storage_field_name)
|
| 376 |
current_val = st.session_state.field_values[selected_name].get(storage_field_name, "")
|
| 377 |
-
value_state_key = f"value_{selected_name}_{storage_field_name}"
|
| 378 |
-
if value_state_key not in st.session_state:
|
| 379 |
-
st.session_state[value_state_key] = current_val
|
| 380 |
|
| 381 |
new_val = st.text_area(
|
| 382 |
"Value (auto-filled by OCR)",
|
| 383 |
-
|
| 384 |
height=80,
|
| 385 |
label_visibility="collapsed",
|
| 386 |
placeholder="Value (auto-filled by OCR)",
|
|
@@ -405,12 +402,13 @@ with col2:
|
|
| 405 |
text = pytesseract.image_to_string(crop, config="--psm 6").strip()
|
| 406 |
if text:
|
| 407 |
st.session_state.field_values[selected_name][storage_field_name] = text
|
| 408 |
-
st.session_state[value_state_key] = text
|
| 409 |
st.success(f"OCR: {text}")
|
| 410 |
else:
|
| 411 |
st.warning("Empty result")
|
| 412 |
except Exception as e:
|
| 413 |
st.error(f"OCR failed: {e}")
|
|
|
|
|
|
|
| 414 |
|
| 415 |
with col_btn3:
|
| 416 |
def delete_rect():
|
|
@@ -562,8 +560,6 @@ with col1:
|
|
| 562 |
text = pytesseract.image_to_string(crop, config="--psm 6").strip()
|
| 563 |
if text:
|
| 564 |
st.session_state.field_values[selected_name][storage_field_name] = text
|
| 565 |
-
value_state_key = f"value_{selected_name}_{storage_field_name}"
|
| 566 |
-
st.session_state[value_state_key] = text
|
| 567 |
st.toast(f"β
OCR: {text[:50]}{'...' if len(text) > 50 else ''}")
|
| 568 |
else:
|
| 569 |
st.toast("β
Rectangle saved (no text detected)")
|
|
@@ -571,5 +567,5 @@ with col1:
|
|
| 571 |
st.toast("β
Rectangle saved")
|
| 572 |
else:
|
| 573 |
st.toast("β
Rectangle saved")
|
| 574 |
-
# force rerun so text
|
| 575 |
st.experimental_rerun()
|
|
|
|
| 264 |
base_field_for_color = SINGLE_FIELDS[0]
|
| 265 |
|
| 266 |
with col2:
|
| 267 |
+
# ========== FIELD SELECTION (RHS) ==========
|
| 268 |
st.markdown("#### π― Field Selection")
|
| 269 |
|
| 270 |
def add_line_item():
|
|
|
|
| 293 |
else:
|
| 294 |
num_items = st.session_state.num_line_items[selected_name]
|
| 295 |
|
| 296 |
+
# Single level of columns inside col2 (no deeper nesting)
|
| 297 |
line_col1, add_col, rem_col = st.columns([2, 1, 1])
|
| 298 |
with line_col1:
|
| 299 |
line_item_options = [f"Line {i+1}" for i in range(num_items)]
|
|
|
|
| 318 |
field_color = FIELD_COLORS.get(base_field_for_color or display_field_name, "#FF0000")
|
| 319 |
st.markdown(f"**Current:** <span style='color:{field_color}'>β</span> {display_field_name}", unsafe_allow_html=True)
|
| 320 |
|
| 321 |
+
# ========== ZOOM CONTROLS (RHS) ==========
|
| 322 |
st.markdown("#### π Zoom")
|
| 323 |
|
| 324 |
current_zoom = st.session_state.zoom_values[selected_name]
|
|
|
|
| 374 |
|
| 375 |
current_rect_orig = st.session_state.field_rects_orig[selected_name].get(storage_field_name)
|
| 376 |
current_val = st.session_state.field_values[selected_name].get(storage_field_name, "")
|
|
|
|
|
|
|
|
|
|
| 377 |
|
| 378 |
new_val = st.text_area(
|
| 379 |
"Value (auto-filled by OCR)",
|
| 380 |
+
value=current_val,
|
| 381 |
height=80,
|
| 382 |
label_visibility="collapsed",
|
| 383 |
placeholder="Value (auto-filled by OCR)",
|
|
|
|
| 402 |
text = pytesseract.image_to_string(crop, config="--psm 6").strip()
|
| 403 |
if text:
|
| 404 |
st.session_state.field_values[selected_name][storage_field_name] = text
|
|
|
|
| 405 |
st.success(f"OCR: {text}")
|
| 406 |
else:
|
| 407 |
st.warning("Empty result")
|
| 408 |
except Exception as e:
|
| 409 |
st.error(f"OCR failed: {e}")
|
| 410 |
+
# force rerun so text area picks up new value
|
| 411 |
+
st.experimental_rerun()
|
| 412 |
|
| 413 |
with col_btn3:
|
| 414 |
def delete_rect():
|
|
|
|
| 560 |
text = pytesseract.image_to_string(crop, config="--psm 6").strip()
|
| 561 |
if text:
|
| 562 |
st.session_state.field_values[selected_name][storage_field_name] = text
|
|
|
|
|
|
|
| 563 |
st.toast(f"β
OCR: {text[:50]}{'...' if len(text) > 50 else ''}")
|
| 564 |
else:
|
| 565 |
st.toast("β
Rectangle saved (no text detected)")
|
|
|
|
| 567 |
st.toast("β
Rectangle saved")
|
| 568 |
else:
|
| 569 |
st.toast("β
Rectangle saved")
|
| 570 |
+
# force rerun so RHS text box shows new OCR value
|
| 571 |
st.experimental_rerun()
|