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

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +12 -12
src/streamlit_app.py CHANGED
@@ -3,43 +3,44 @@ from PIL import Image
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,6 +51,5 @@ if img_data is not None:
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)
 
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
+ # βœ… Add a confirmation the photo was captured
12
+ st.write("πŸ“Έ Waiting for image capture...")
13
+
14
+ if img_data:
15
+ st.write("βœ… Image captured successfully")
16
+
17
+ # βœ… Check file size
18
  if len(img_data.getvalue()) > 5 * 1024 * 1024:
19
  st.error("❌ Image too large (>5MB). Please try again.")
20
  st.stop()
21
 
 
22
  image = Image.open(img_data)
23
  st.image(image, caption="πŸ“Έ Snapshot", use_column_width=True)
24
 
 
25
  with st.spinner("πŸ” Extracting weight..."):
26
  weight, confidence = extract_weight_from_image(image)
27
 
28
+ # βœ… DEBUG display
29
  st.write(f"πŸ› οΈ DEBUG: weight = {weight}, confidence = {confidence}")
30
 
31
+ # βœ… Retry logic
32
  if not weight or confidence < 80:
33
  st.error(f"⚠️ OCR confidence too low ({int(confidence)}%). Please retake the image.")
34
  if st.button("πŸ” Try Again"):
35
  st.experimental_rerun()
36
  st.stop()
37
 
38
+ # βœ… Show result
39
  st.success(f"βœ… Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
40
 
41
+ # βœ… Salesforce integration
42
  device_id = "BAL-001"
43
+ image_url = ""
44
 
45
  encoded_weight = urllib.parse.quote(str(weight))
46
  encoded_device = urllib.parse.quote(device_id)
 
51
  f"weight_logger_page?WeightInput={encoded_weight}&DeviceID={encoded_device}&ImageURL={encoded_image_url}"
52
  )
53
 
 
54
  st.markdown("### πŸ“€ Send to Salesforce")
55
  st.markdown(f"[βœ… Click here to confirm and log in Salesforce]({salesforce_url})", unsafe_allow_html=True)