Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +14 -13
src/streamlit_app.py
CHANGED
@@ -6,21 +6,21 @@ 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 "
|
11 |
-
st.session_state.
|
12 |
|
13 |
-
# π
|
14 |
if st.button("π Clear / Retake Photo"):
|
15 |
-
st.session_state.
|
16 |
-
st.rerun()
|
17 |
|
18 |
-
#
|
19 |
-
if st.session_state.
|
20 |
-
st.session_state.
|
21 |
-
st.
|
22 |
|
23 |
-
#
|
24 |
img_data = st.camera_input("π· Capture the weight display")
|
25 |
|
26 |
if img_data:
|
@@ -41,14 +41,14 @@ if img_data:
|
|
41 |
if not weight or confidence < 80:
|
42 |
st.error(f"β οΈ OCR confidence too low ({int(confidence)}%). Please retake the photo.")
|
43 |
if st.button("π Retake Photo"):
|
44 |
-
st.session_state.
|
45 |
st.rerun()
|
46 |
st.stop()
|
47 |
|
48 |
st.success(f"β
Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
|
49 |
|
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)
|
@@ -61,3 +61,4 @@ if img_data:
|
|
61 |
|
62 |
st.markdown("### π€ Send to Salesforce")
|
63 |
st.markdown(f"[β
Click here to confirm and log in Salesforce]({salesforce_url})", unsafe_allow_html=True)
|
|
|
|
6 |
st.set_page_config(page_title="βοΈ Auto Weight Logger", layout="centered")
|
7 |
st.title("βοΈ Auto Weight Logger")
|
8 |
|
9 |
+
# β
Session state to control camera
|
10 |
+
if "retake" not in st.session_state:
|
11 |
+
st.session_state.retake = False
|
12 |
|
13 |
+
# π Retake Button
|
14 |
if st.button("π Clear / Retake Photo"):
|
15 |
+
st.session_state.retake = True
|
16 |
+
st.rerun()
|
17 |
|
18 |
+
# β
If this is the rerun after clearing, reset and skip camera once
|
19 |
+
if st.session_state.retake:
|
20 |
+
st.session_state.retake = False
|
21 |
+
st.rerun()
|
22 |
|
23 |
+
# β
At this point, camera will always be shown
|
24 |
img_data = st.camera_input("π· Capture the weight display")
|
25 |
|
26 |
if img_data:
|
|
|
41 |
if not weight or confidence < 80:
|
42 |
st.error(f"β οΈ OCR confidence too low ({int(confidence)}%). Please retake the photo.")
|
43 |
if st.button("π Retake Photo"):
|
44 |
+
st.session_state.retake = True
|
45 |
st.rerun()
|
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)
|
|
|
61 |
|
62 |
st.markdown("### π€ Send to Salesforce")
|
63 |
st.markdown(f"[β
Click here to confirm and log in Salesforce]({salesforce_url})", unsafe_allow_html=True)
|
64 |
+
|