Update src/streamlit_app.py
Browse files- 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("π
|
30 |
st.experimental_rerun()
|
31 |
st.stop()
|
32 |
|
33 |
-
|
|
|
|
|
34 |
device_id = "BAL-001"
|
35 |
-
image_url = "" #
|
36 |
-
|
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 |
-
|
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)
|