Sanjayraju30 commited on
Commit
422d11e
Β·
verified Β·
1 Parent(s): e9a7c89

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +11 -2
src/streamlit_app.py CHANGED
@@ -3,35 +3,43 @@ 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
  img_data = st.camera_input("πŸ“· Capture the weight display")
10
 
11
  if img_data is not None:
 
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
- # DEBUG: This helps you test OCR output
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
 
36
  encoded_weight = urllib.parse.quote(str(weight))
37
  encoded_device = urllib.parse.quote(device_id)
@@ -42,5 +50,6 @@ if img_data is not None:
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)
 
3
  from ocr_engine import extract_weight_from_image
4
  import urllib.parse
5
 
6
+ # βœ… App configuration
7
  st.set_page_config(page_title="βš–οΈ Auto Weight Logger", layout="centered")
8
  st.title("βš–οΈ Auto Weight Logger")
9
 
10
+ # βœ… Capture image from camera
11
  img_data = st.camera_input("πŸ“· Capture the weight display")
12
 
13
  if img_data is not None:
14
+ # βœ… Check for file size
15
  if len(img_data.getvalue()) > 5 * 1024 * 1024:
16
  st.error("❌ Image too large (>5MB). Please try again.")
17
  st.stop()
18
 
19
+ # βœ… Show captured image
20
  image = Image.open(img_data)
21
  st.image(image, caption="πŸ“Έ Snapshot", use_column_width=True)
22
 
23
+ # βœ… Run OCR
24
  with st.spinner("πŸ” Extracting weight..."):
25
  weight, confidence = extract_weight_from_image(image)
26
 
27
+ # βœ… Show debug info (can be removed later)
28
  st.write(f"πŸ› οΈ DEBUG: weight = {weight}, confidence = {confidence}")
29
 
30
+ # βœ… Retry if OCR failed or confidence too low
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("πŸ” Try Again"):
34
  st.experimental_rerun()
35
  st.stop()
36
 
37
+ # βœ… Show success
38
  st.success(f"βœ… Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
39
 
40
+ # βœ… Prepare Salesforce URL
41
  device_id = "BAL-001"
42
+ image_url = "" # Leave blank unless you host image
43
 
44
  encoded_weight = urllib.parse.quote(str(weight))
45
  encoded_device = urllib.parse.quote(device_id)
 
50
  f"weight_logger_page?WeightInput={encoded_weight}&DeviceID={encoded_device}&ImageURL={encoded_image_url}"
51
  )
52
 
53
+ # βœ… Send to Salesforce
54
  st.markdown("### πŸ“€ Send to Salesforce")
55
  st.markdown(f"[βœ… Click here to confirm and log in Salesforce]({salesforce_url})", unsafe_allow_html=True)