Update src/streamlit_app.py
Browse files- src/streamlit_app.py +10 -6
src/streamlit_app.py
CHANGED
@@ -6,16 +6,17 @@ 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 st.button("π Restart App"):
|
11 |
-
st.
|
12 |
|
13 |
-
#
|
14 |
img_data = st.camera_input("π· Capture the weight display")
|
15 |
|
16 |
if img_data:
|
17 |
st.success("β
Image captured successfully!")
|
18 |
|
|
|
19 |
if len(img_data.getvalue()) > 5 * 1024 * 1024:
|
20 |
st.error("β Image too large (>5MB). Please try again.")
|
21 |
st.stop()
|
@@ -28,18 +29,20 @@ if img_data:
|
|
28 |
|
29 |
st.write(f"π οΈ DEBUG: weight = {weight}, confidence = {confidence}")
|
30 |
|
|
|
31 |
if not weight or confidence < 80:
|
32 |
st.error(f"β οΈ OCR confidence too low ({int(confidence)}%). Please retake the image.")
|
33 |
if st.button("π Retry"):
|
34 |
-
st.
|
35 |
st.stop()
|
36 |
|
37 |
st.success(f"β
Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
|
38 |
|
39 |
-
#
|
40 |
device_id = "BAL-001"
|
41 |
-
image_url = "" # Optional
|
42 |
|
|
|
43 |
encoded_weight = urllib.parse.quote(str(weight))
|
44 |
encoded_device = urllib.parse.quote(device_id)
|
45 |
encoded_image_url = urllib.parse.quote(image_url)
|
@@ -51,3 +54,4 @@ if img_data:
|
|
51 |
|
52 |
st.markdown("### π€ Send to Salesforce")
|
53 |
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 |
+
# π Restart App Button
|
10 |
if st.button("π Restart App"):
|
11 |
+
st.rerun()
|
12 |
|
13 |
+
# π· Capture Image
|
14 |
img_data = st.camera_input("π· Capture the weight display")
|
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 |
|
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 Site Parameters
|
42 |
device_id = "BAL-001"
|
43 |
+
image_url = "" # Optional 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 |
|
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 |
+
|