Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +24 -15
src/streamlit_app.py
CHANGED
@@ -6,26 +6,33 @@ import urllib.parse
|
|
6 |
st.set_page_config(page_title="βοΈ Auto Weight Logger", layout="centered")
|
7 |
st.title("βοΈ Auto Weight Logger")
|
8 |
|
9 |
-
# β
Session state to
|
10 |
-
if "
|
11 |
-
st.session_state.
|
|
|
|
|
12 |
|
13 |
-
# π Retake Button
|
14 |
if st.button("π Clear / Retake Photo"):
|
15 |
-
st.session_state.
|
16 |
-
st.
|
|
|
17 |
|
18 |
-
# β
|
19 |
-
if st.session_state.
|
20 |
-
st.
|
21 |
-
st.rerun()
|
22 |
|
23 |
-
|
24 |
-
|
|
|
|
|
25 |
|
26 |
-
|
|
|
27 |
st.success("β
Image captured successfully!")
|
28 |
|
|
|
|
|
29 |
if len(img_data.getvalue()) > 5 * 1024 * 1024:
|
30 |
st.error("β Image too large (>5MB). Please try again.")
|
31 |
st.stop()
|
@@ -41,12 +48,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.
|
|
|
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 |
|
|
|
6 |
st.set_page_config(page_title="βοΈ Auto Weight Logger", layout="centered")
|
7 |
st.title("βοΈ Auto Weight Logger")
|
8 |
|
9 |
+
# β
Session state to manage retake and image
|
10 |
+
if "image_captured" not in st.session_state:
|
11 |
+
st.session_state.image_captured = False
|
12 |
+
if "image_data" not in st.session_state:
|
13 |
+
st.session_state.image_data = None
|
14 |
|
15 |
+
# π Retake / Clear Button
|
16 |
if st.button("π Clear / Retake Photo"):
|
17 |
+
st.session_state.image_captured = False
|
18 |
+
st.session_state.image_data = None
|
19 |
+
st.experimental_rerun()
|
20 |
|
21 |
+
# β
Show camera only if no image captured
|
22 |
+
if not st.session_state.image_captured:
|
23 |
+
img_data = st.camera_input("π· Capture the weight display")
|
|
|
24 |
|
25 |
+
if img_data:
|
26 |
+
st.session_state.image_data = img_data
|
27 |
+
st.session_state.image_captured = True
|
28 |
+
st.experimental_rerun()
|
29 |
|
30 |
+
# β
If image is already captured
|
31 |
+
if st.session_state.image_captured and st.session_state.image_data:
|
32 |
st.success("β
Image captured successfully!")
|
33 |
|
34 |
+
img_data = st.session_state.image_data
|
35 |
+
|
36 |
if len(img_data.getvalue()) > 5 * 1024 * 1024:
|
37 |
st.error("β Image too large (>5MB). Please try again.")
|
38 |
st.stop()
|
|
|
48 |
if not weight or confidence < 80:
|
49 |
st.error(f"β οΈ OCR confidence too low ({int(confidence)}%). Please retake the photo.")
|
50 |
if st.button("π Retake Photo"):
|
51 |
+
st.session_state.image_captured = False
|
52 |
+
st.session_state.image_data = None
|
53 |
+
st.experimental_rerun()
|
54 |
st.stop()
|
55 |
|
56 |
st.success(f"β
Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
|
57 |
|
58 |
+
# π Salesforce link logic
|
59 |
device_id = "BAL-001"
|
60 |
image_url = "" # Optional
|
61 |
|