Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +10 -17
src/streamlit_app.py
CHANGED
@@ -6,29 +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 "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 |
-
#
|
16 |
if st.button("π Clear / Retake Photo"):
|
17 |
-
st.session_state.image_captured = False
|
18 |
st.session_state.image_data = None
|
19 |
-
st.rerun()
|
20 |
|
21 |
-
#
|
22 |
-
if
|
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.
|
28 |
-
st.rerun()
|
29 |
|
30 |
-
#
|
31 |
-
if st.session_state.
|
32 |
st.success("β
Image captured successfully!")
|
33 |
|
34 |
img_data = st.session_state.image_data
|
@@ -48,16 +42,15 @@ if st.session_state.image_captured and st.session_state.image_data:
|
|
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.
|
54 |
st.stop()
|
55 |
|
56 |
st.success(f"β
Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
|
57 |
|
58 |
-
# π Salesforce
|
59 |
device_id = "BAL-001"
|
60 |
-
image_url = ""
|
61 |
|
62 |
encoded_weight = urllib.parse.quote(str(weight))
|
63 |
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 |
+
# Initialize session state
|
|
|
|
|
10 |
if "image_data" not in st.session_state:
|
11 |
st.session_state.image_data = None
|
12 |
|
13 |
+
# Clear button to retake image
|
14 |
if st.button("π Clear / Retake Photo"):
|
|
|
15 |
st.session_state.image_data = None
|
|
|
16 |
|
17 |
+
# Show camera if no image captured
|
18 |
+
if st.session_state.image_data is None:
|
19 |
img_data = st.camera_input("π· Capture the weight display")
|
|
|
20 |
if img_data:
|
21 |
st.session_state.image_data = img_data
|
22 |
+
st.experimental_rerun() # NOTE: Works fine in most Streamlit cloud spaces
|
|
|
23 |
|
24 |
+
# Show captured image and process
|
25 |
+
if st.session_state.image_data:
|
26 |
st.success("β
Image captured successfully!")
|
27 |
|
28 |
img_data = st.session_state.image_data
|
|
|
42 |
if not weight or confidence < 80:
|
43 |
st.error(f"β οΈ OCR confidence too low ({int(confidence)}%). Please retake the photo.")
|
44 |
if st.button("π Retake Photo"):
|
|
|
45 |
st.session_state.image_data = None
|
46 |
+
st.experimental_rerun()
|
47 |
st.stop()
|
48 |
|
49 |
st.success(f"β
Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
|
50 |
|
51 |
+
# π Salesforce URL
|
52 |
device_id = "BAL-001"
|
53 |
+
image_url = ""
|
54 |
|
55 |
encoded_weight = urllib.parse.quote(str(weight))
|
56 |
encoded_device = urllib.parse.quote(device_id)
|