Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +26 -60
src/streamlit_app.py
CHANGED
@@ -1,64 +1,30 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
-
from ocr_engine import extract_weight_from_image
|
4 |
-
import urllib.parse
|
5 |
|
6 |
-
st.
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
st.
|
17 |
-
|
18 |
-
|
19 |
-
if
|
20 |
-
|
21 |
-
st.
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
image = Image.open(img_data)
|
34 |
-
st.image(image, caption="πΈ Snapshot", use_column_width=True)
|
35 |
-
|
36 |
-
with st.spinner("π Extracting weight..."):
|
37 |
-
weight, confidence = extract_weight_from_image(image)
|
38 |
-
|
39 |
-
st.write(f"π οΈ DEBUG: weight = {weight}, confidence = {confidence}")
|
40 |
-
|
41 |
-
if not weight or confidence < 80:
|
42 |
-
st.error(f"β οΈ OCR confidence too low ({int(confidence)}%). Please retake the photo.")
|
43 |
-
if st.button("π Retake Photo"):
|
44 |
-
st.session_state.retake = True
|
45 |
-
st.rerun()
|
46 |
-
st.stop()
|
47 |
-
|
48 |
-
st.success(f"β
Detected Weight: {weight} g (Confidence: {int(confidence)}%)")
|
49 |
-
|
50 |
-
device_id = "BAL-001"
|
51 |
-
image_url = "" # Optional
|
52 |
-
|
53 |
-
encoded_weight = urllib.parse.quote(str(weight))
|
54 |
-
encoded_device = urllib.parse.quote(device_id)
|
55 |
-
encoded_image_url = urllib.parse.quote(image_url)
|
56 |
-
|
57 |
-
salesforce_url = (
|
58 |
-
"https://autoweightlogger-dev-ed.my.salesforce-sites.com/"
|
59 |
-
f"weight_logger_page?WeightInput={encoded_weight}&DeviceID={encoded_device}&ImageURL={encoded_image_url}"
|
60 |
-
)
|
61 |
-
|
62 |
-
st.markdown("### π€ Send to Salesforce")
|
63 |
-
st.markdown(f"[β
Click here to confirm and log in Salesforce]({salesforce_url})", unsafe_allow_html=True)
|
64 |
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
|
|
|
|
3 |
|
4 |
+
st.title("πΈ Auto Weight Logger with Retake Option")
|
5 |
+
|
6 |
+
# Session state to track if image is captured
|
7 |
+
if 'captured' not in st.session_state:
|
8 |
+
st.session_state.captured = False
|
9 |
+
if 'image' not in st.session_state:
|
10 |
+
st.session_state.image = None
|
11 |
+
|
12 |
+
# Function to reset camera
|
13 |
+
def retake():
|
14 |
+
st.session_state.captured = False
|
15 |
+
st.session_state.image = None
|
16 |
+
|
17 |
+
# Only show camera if image is not captured
|
18 |
+
if not st.session_state.captured:
|
19 |
+
image = st.camera_input("Take a picture")
|
20 |
+
if image:
|
21 |
+
st.session_state.image = image
|
22 |
+
st.session_state.captured = True
|
23 |
+
|
24 |
+
# If image is captured, show options
|
25 |
+
if st.session_state.captured and st.session_state.image:
|
26 |
+
st.image(st.session_state.image, caption="Captured Image", use_column_width=True)
|
27 |
+
st.button("Retake", on_click=retake)
|
28 |
+
st.success("β
Image captured successfully.")
|
29 |
+
# You can add OCR or Salesforce upload button here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|