Update src/streamlit_app.py
Browse files- src/streamlit_app.py +12 -12
src/streamlit_app.py
CHANGED
@@ -6,22 +6,23 @@ import urllib.parse
|
|
6 |
st.set_page_config(page_title="βοΈ Auto Weight Logger", layout="centered")
|
7 |
st.title("βοΈ Auto Weight Logger")
|
8 |
|
9 |
-
#
|
10 |
if "reset" not in st.session_state:
|
11 |
st.session_state.reset = False
|
12 |
|
13 |
-
#
|
14 |
-
if st.
|
15 |
-
st.session_state.reset =
|
16 |
st.rerun()
|
17 |
|
18 |
-
#
|
19 |
-
if
|
20 |
-
|
21 |
-
else:
|
22 |
-
st.info("πΈ Photo cleared. Click Restart to take again.")
|
23 |
st.stop()
|
24 |
|
|
|
|
|
|
|
25 |
if img_data:
|
26 |
st.success("β
Image captured successfully!")
|
27 |
|
@@ -41,14 +42,13 @@ if img_data:
|
|
41 |
st.error(f"β οΈ OCR confidence too low ({int(confidence)}%). Please retake the image.")
|
42 |
if st.button("π Retry"):
|
43 |
st.session_state.reset = True
|
44 |
-
st.
|
45 |
st.stop()
|
46 |
|
47 |
st.success(f"β
Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
|
48 |
|
49 |
-
# Salesforce URL Parameters
|
50 |
device_id = "BAL-001"
|
51 |
-
image_url = "" #
|
52 |
|
53 |
encoded_weight = urllib.parse.quote(str(weight))
|
54 |
encoded_device = urllib.parse.quote(device_id)
|
|
|
6 |
st.set_page_config(page_title="βοΈ Auto Weight Logger", layout="centered")
|
7 |
st.title("βοΈ Auto Weight Logger")
|
8 |
|
9 |
+
# Setup session state
|
10 |
if "reset" not in st.session_state:
|
11 |
st.session_state.reset = False
|
12 |
|
13 |
+
# Handle clear/restart logic
|
14 |
+
if st.session_state.reset:
|
15 |
+
st.session_state.reset = False # β
Reset after 1 rerun
|
16 |
st.rerun()
|
17 |
|
18 |
+
# Show clear button
|
19 |
+
if st.button("π Clear Photo"):
|
20 |
+
st.session_state.reset = True
|
|
|
|
|
21 |
st.stop()
|
22 |
|
23 |
+
# Camera input
|
24 |
+
img_data = st.camera_input("π· Capture the weight display")
|
25 |
+
|
26 |
if img_data:
|
27 |
st.success("β
Image captured successfully!")
|
28 |
|
|
|
42 |
st.error(f"β οΈ OCR confidence too low ({int(confidence)}%). Please retake the image.")
|
43 |
if st.button("π Retry"):
|
44 |
st.session_state.reset = True
|
45 |
+
st.stop()
|
46 |
st.stop()
|
47 |
|
48 |
st.success(f"β
Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
|
49 |
|
|
|
50 |
device_id = "BAL-001"
|
51 |
+
image_url = "" # Optional
|
52 |
|
53 |
encoded_weight = urllib.parse.quote(str(weight))
|
54 |
encoded_device = urllib.parse.quote(device_id)
|