Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- 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 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
-
# β
|
28 |
st.write(f"π οΈ DEBUG: weight = {weight}, confidence = {confidence}")
|
29 |
|
30 |
-
# β
Retry
|
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
|
38 |
st.success(f"β
Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
|
39 |
|
40 |
-
# β
|
41 |
device_id = "BAL-001"
|
42 |
-
image_url = ""
|
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)
|