Sanjayraju30 commited on
Commit
844e1ad
Β·
verified Β·
1 Parent(s): 0ed7e8f

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +38 -3
src/streamlit_app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from PIL import Image
3
  from ocr_engine import extract_weight_from_image
 
4
 
5
  st.set_page_config(page_title="Auto Weight Logger", layout="centered")
6
  st.title("βš–οΈ Auto Weight Logger")
@@ -8,10 +9,44 @@ st.title("βš–οΈ Auto Weight Logger")
8
  img_data = st.camera_input("πŸ“· Capture the weight display")
9
 
10
  if img_data:
 
 
 
 
 
 
11
  image = Image.open(img_data)
12
  st.image(image, caption="πŸ“Έ Snapshot", use_column_width=True)
13
 
14
- with st.spinner("Extracting weight..."):
15
- weight = extract_weight_from_image(image)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- st.success(f"βœ… Detected Weight: {weight} g")
 
 
 
1
  import streamlit as st
2
  from PIL import Image
3
  from ocr_engine import extract_weight_from_image
4
+ import urllib.parse
5
 
6
  st.set_page_config(page_title="Auto Weight Logger", layout="centered")
7
  st.title("βš–οΈ Auto Weight Logger")
 
9
  img_data = st.camera_input("πŸ“· Capture the weight display")
10
 
11
  if img_data:
12
+ # βœ… BRD: Check file size limit
13
+ if len(img_data.getvalue()) > 5 * 1024 * 1024:
14
+ st.error("❌ Image too large (>5MB). Please try again.")
15
+ st.stop()
16
+
17
+ # βœ… Preview the image
18
  image = Image.open(img_data)
19
  st.image(image, caption="πŸ“Έ Snapshot", use_column_width=True)
20
 
21
+ # βœ… Extract weight and confidence
22
+ with st.spinner("πŸ” Extracting weight..."):
23
+ weight, confidence = extract_weight_from_image(image)
24
+
25
+ # βœ… BRD: Confidence threshold check
26
+ if not weight or confidence < 80:
27
+ st.error(f"⚠️ OCR confidence too low ({int(confidence)}%). Please retake the image.")
28
+ if st.button("πŸ” Try Again"):
29
+ st.experimental_rerun()
30
+ st.stop()
31
+
32
+ # βœ… Show extracted weight
33
+ st.success(f"βœ… Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
34
+
35
+ # βœ… Set device ID and image URL
36
+ device_id = "BAL-001"
37
+ image_url = "" # optional, leave blank unless you host the image
38
+
39
+ # βœ… Encode URL parameters
40
+ encoded_weight = urllib.parse.quote(str(weight))
41
+ encoded_device = urllib.parse.quote(device_id)
42
+ encoded_image_url = urllib.parse.quote(image_url)
43
+
44
+ # βœ… Salesforce link
45
+ salesforce_url = (
46
+ f"https://autoweightlogger-dev-ed.my.salesforce-sites.com/"
47
+ f"weight_logger_page?WeightInput={encoded_weight}&DeviceID={encoded_device}&ImageURL={encoded_image_url}"
48
+ )
49
 
50
+ # βœ… Show link to confirm weight in Salesforce
51
+ st.markdown("### πŸ“€ Send to Salesforce")
52
+ st.markdown(f"[βœ… Click here to confirm and log in Salesforce]({salesforce_url})", unsafe_allow_html=True)