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

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +12 -21
src/streamlit_app.py CHANGED
@@ -2,11 +2,15 @@ import streamlit as st
2
  from PIL import Image
3
  from ocr_engine import extract_weight_from_image
4
  import urllib.parse
5
- from datetime import datetime
6
 
7
  st.set_page_config(page_title="βš–οΈ Auto Weight Logger", layout="centered")
8
  st.title("βš–οΈ Auto Weight Logger")
9
 
 
 
 
 
 
10
  img_data = st.camera_input("πŸ“· Capture the weight display")
11
 
12
  if img_data:
@@ -26,37 +30,24 @@ if img_data:
26
 
27
  if not weight or confidence < 80:
28
  st.error(f"⚠️ OCR confidence too low ({int(confidence)}%). Please retake the image.")
29
- if st.button("πŸ” Try Again"):
30
  st.experimental_rerun()
31
  st.stop()
32
 
33
- # βœ… Prepare data for preview and URL
 
 
34
  device_id = "BAL-001"
35
- image_url = "" # optional - add later if you host the image
36
- captured_at = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
37
- status = "Pending Submission"
38
-
39
- # βœ… Show full preview
40
- st.markdown("### πŸ“‹ Record Preview (before sending to Salesforce)")
41
- st.write({
42
- "Auto Number": "Will be generated in Salesforce",
43
- "Captured Weight": f"{weight} g",
44
- "Captured At": captured_at,
45
- "Snapshot Image": "Attached" if image_url else "Not available",
46
- "Device ID": device_id,
47
- "Status": status
48
- })
49
-
50
- # βœ… Encode for Salesforce
51
  encoded_weight = urllib.parse.quote(str(weight))
52
  encoded_device = urllib.parse.quote(device_id)
53
  encoded_image_url = urllib.parse.quote(image_url)
54
 
55
  salesforce_url = (
56
- f"https://autoweightlogger-dev-ed.my.salesforce-sites.com/"
57
  f"weight_logger_page?WeightInput={encoded_weight}&DeviceID={encoded_device}&ImageURL={encoded_image_url}"
58
  )
59
 
60
- # βœ… Show Salesforce link
61
  st.markdown("### πŸ“€ Send to Salesforce")
62
  st.markdown(f"[βœ… Click here to confirm and log in Salesforce]({salesforce_url})", unsafe_allow_html=True)
 
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")
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:
 
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)
46
 
47
  salesforce_url = (
48
+ "https://autoweightlogger-dev-ed.my.salesforce-sites.com/"
49
  f"weight_logger_page?WeightInput={encoded_weight}&DeviceID={encoded_device}&ImageURL={encoded_image_url}"
50
  )
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)