Sanjayraju30 commited on
Commit
f038ea6
Β·
verified Β·
1 Parent(s): cecd6a8

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +2 -9
src/streamlit_app.py CHANGED
@@ -9,33 +9,27 @@ st.title("βš–οΈ Auto Weight Logger")
9
  img_data = st.camera_input("πŸ“· Capture the weight display")
10
 
11
  if img_data:
12
- # βœ… Check file size (BRD requirement)
13
  if len(img_data.getvalue()) > 5 * 1024 * 1024:
14
  st.error("❌ Image too large (>5MB). Please try again.")
15
  st.stop()
16
 
17
- # βœ… Show the image to user
18
  image = Image.open(img_data)
19
  st.image(image, caption="πŸ“Έ Snapshot", use_column_width=True)
20
 
21
- # βœ… Run OCR to get weight and confidence
22
  with st.spinner("πŸ” Extracting weight..."):
23
  weight, confidence = extract_weight_from_image(image)
24
 
25
- # βœ… DEBUG: Uncomment this to see raw output
26
- # st.write(f"DEBUG: weight = {weight}, confidence = {confidence}")
27
 
28
- # βœ… Handle OCR failure or low confidence
29
  if not weight or confidence < 80:
30
  st.error(f"⚠️ OCR confidence too low ({int(confidence)}%). Please retake the image.")
31
  if st.button("πŸ” Try Again"):
32
  st.experimental_rerun()
33
  st.stop()
34
 
35
- # βœ… Show success with weight and confidence
36
  st.success(f"βœ… Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
37
 
38
- # βœ… Prepare Salesforce link
39
  device_id = "BAL-001"
40
  image_url = ""
41
 
@@ -48,6 +42,5 @@ if img_data:
48
  f"weight_logger_page?WeightInput={encoded_weight}&DeviceID={encoded_device}&ImageURL={encoded_image_url}"
49
  )
50
 
51
- # βœ… Show Salesforce confirmation link
52
  st.markdown("### πŸ“€ Send to Salesforce")
53
  st.markdown(f"[βœ… Click here to confirm and log in Salesforce]({salesforce_url})", unsafe_allow_html=True)
 
9
  img_data = st.camera_input("πŸ“· Capture the weight display")
10
 
11
  if img_data:
 
12
  if len(img_data.getvalue()) > 5 * 1024 * 1024:
13
  st.error("❌ Image too large (>5MB). Please try again.")
14
  st.stop()
15
 
 
16
  image = Image.open(img_data)
17
  st.image(image, caption="πŸ“Έ Snapshot", use_column_width=True)
18
 
 
19
  with st.spinner("πŸ” Extracting weight..."):
20
  weight, confidence = extract_weight_from_image(image)
21
 
22
+ # βœ… Show debug info (you can delete this later)
23
+ st.write(f"πŸ› οΈ DEBUG: weight = {weight}, confidence = {confidence}")
24
 
 
25
  if not weight or confidence < 80:
26
  st.error(f"⚠️ OCR confidence too low ({int(confidence)}%). Please retake the image.")
27
  if st.button("πŸ” Try Again"):
28
  st.experimental_rerun()
29
  st.stop()
30
 
 
31
  st.success(f"βœ… Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
32
 
 
33
  device_id = "BAL-001"
34
  image_url = ""
35
 
 
42
  f"weight_logger_page?WeightInput={encoded_weight}&DeviceID={encoded_device}&ImageURL={encoded_image_url}"
43
  )
44
 
 
45
  st.markdown("### πŸ“€ Send to Salesforce")
46
  st.markdown(f"[βœ… Click here to confirm and log in Salesforce]({salesforce_url})", unsafe_allow_html=True)