Sanjayraju30 commited on
Commit
b985185
Β·
verified Β·
1 Parent(s): 44fd5b1

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +12 -12
src/streamlit_app.py CHANGED
@@ -6,22 +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
- # βœ… 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
 
@@ -41,14 +42,13 @@ if img_data:
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)
 
6
  st.set_page_config(page_title="βš–οΈ Auto Weight Logger", layout="centered")
7
  st.title("βš–οΈ Auto Weight Logger")
8
 
9
+ # Setup session state
10
  if "reset" not in st.session_state:
11
  st.session_state.reset = False
12
 
13
+ # Handle clear/restart logic
14
+ if st.session_state.reset:
15
+ st.session_state.reset = False # βœ… Reset after 1 rerun
16
  st.rerun()
17
 
18
+ # Show clear button
19
+ if st.button("πŸ” Clear Photo"):
20
+ st.session_state.reset = True
 
 
21
  st.stop()
22
 
23
+ # Camera input
24
+ img_data = st.camera_input("πŸ“· Capture the weight display")
25
+
26
  if img_data:
27
  st.success("βœ… Image captured successfully!")
28
 
 
42
  st.error(f"⚠️ OCR confidence too low ({int(confidence)}%). Please retake the image.")
43
  if st.button("πŸ” Retry"):
44
  st.session_state.reset = True
45
+ st.stop()
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)