Sanjayraju30 commited on
Commit
d54c470
Β·
verified Β·
1 Parent(s): 19e20f2

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # βœ… Manage camera state
10
- if "clear" not in st.session_state:
11
- st.session_state.clear = False
12
 
13
- # πŸ”˜ Clear / Retake Photo button
14
  if st.button("πŸ” Clear / Retake Photo"):
15
- st.session_state.clear = True
16
- st.rerun() # βœ… use st.rerun, not experimental_rerun
17
 
18
- # 🧼 Skip this run if clearing
19
- if st.session_state.clear:
20
- st.session_state.clear = False
21
- st.stop()
22
 
23
- # πŸ“· Camera Input
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.clear = 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 = ""
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
+