Update src/streamlit_app.py
Browse files- src/streamlit_app.py +16 -10
src/streamlit_app.py
CHANGED
@@ -6,17 +6,25 @@ 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.rerun()
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
if img_data:
|
17 |
st.success("β
Image captured successfully!")
|
18 |
|
19 |
-
# Optional file size check
|
20 |
if len(img_data.getvalue()) > 5 * 1024 * 1024:
|
21 |
st.error("β Image too large (>5MB). Please try again.")
|
22 |
st.stop()
|
@@ -29,20 +37,19 @@ if img_data:
|
|
29 |
|
30 |
st.write(f"π οΈ DEBUG: weight = {weight}, confidence = {confidence}")
|
31 |
|
32 |
-
# Confidence check
|
33 |
if not weight or confidence < 80:
|
34 |
st.error(f"β οΈ OCR confidence too low ({int(confidence)}%). Please retake the image.")
|
35 |
if st.button("π Retry"):
|
|
|
36 |
st.rerun()
|
37 |
st.stop()
|
38 |
|
39 |
st.success(f"β
Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
|
40 |
|
41 |
-
# Salesforce
|
42 |
device_id = "BAL-001"
|
43 |
-
image_url = "" #
|
44 |
|
45 |
-
# Encode parameters
|
46 |
encoded_weight = urllib.parse.quote(str(weight))
|
47 |
encoded_device = urllib.parse.quote(device_id)
|
48 |
encoded_image_url = urllib.parse.quote(image_url)
|
@@ -54,4 +61,3 @@ if img_data:
|
|
54 |
|
55 |
st.markdown("### π€ Send to Salesforce")
|
56 |
st.markdown(f"[β
Click here to confirm and log in Salesforce]({salesforce_url})", unsafe_allow_html=True)
|
57 |
-
|
|
|
6 |
st.set_page_config(page_title="βοΈ Auto Weight Logger", layout="centered")
|
7 |
st.title("βοΈ Auto Weight Logger")
|
8 |
|
9 |
+
# β
Use session_state to manage resets
|
10 |
+
if "reset" not in st.session_state:
|
11 |
+
st.session_state.reset = False
|
12 |
+
|
13 |
+
# π Restart App
|
14 |
+
if st.button("π Restart / Clear Photo"):
|
15 |
+
st.session_state.reset = True
|
16 |
st.rerun()
|
17 |
|
18 |
+
# Only show camera input if not resetting
|
19 |
+
if not st.session_state.reset:
|
20 |
+
img_data = st.camera_input("π· Capture the weight display")
|
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 |
|
|
|
28 |
if len(img_data.getvalue()) > 5 * 1024 * 1024:
|
29 |
st.error("β Image too large (>5MB). Please try again.")
|
30 |
st.stop()
|
|
|
37 |
|
38 |
st.write(f"π οΈ DEBUG: weight = {weight}, confidence = {confidence}")
|
39 |
|
|
|
40 |
if not weight or confidence < 80:
|
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.rerun()
|
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 = "" # You can host and link if needed
|
52 |
|
|
|
53 |
encoded_weight = urllib.parse.quote(str(weight))
|
54 |
encoded_device = urllib.parse.quote(device_id)
|
55 |
encoded_image_url = urllib.parse.quote(image_url)
|
|
|
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)
|
|