Sanjayraju30 commited on
Commit
9561543
Β·
verified Β·
1 Parent(s): f352fb7

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # Show restart button at the top
10
  if st.button("πŸ” Restart App"):
11
- st.experimental_rerun()
12
 
13
- # Camera input
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.experimental_rerun()
35
  st.stop()
36
 
37
  st.success(f"βœ… Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
38
 
39
- # Send to Salesforce
40
  device_id = "BAL-001"
41
- image_url = "" # Optional, can be a hosted link if added
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
+