Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,20 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image, UnidentifiedImageError
|
| 3 |
-
import io
|
| 4 |
from datetime import datetime
|
| 5 |
import pytz
|
| 6 |
from ocr_engine import extract_weight_from_image
|
| 7 |
|
|
|
|
| 8 |
st.set_page_config(page_title="βοΈ Auto Weight Logger", layout="centered")
|
| 9 |
st.title("βοΈ Auto Weight Logger")
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
if "camera_key" not in st.session_state:
|
| 12 |
st.session_state["camera_key"] = 0
|
| 13 |
|
| 14 |
-
#
|
| 15 |
col1, col2 = st.columns(2)
|
| 16 |
with col1:
|
| 17 |
uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
|
@@ -33,26 +36,20 @@ elif camera_image:
|
|
| 33 |
except UnidentifiedImageError:
|
| 34 |
st.error("Invalid camera image.")
|
| 35 |
|
| 36 |
-
# Process
|
| 37 |
if image:
|
| 38 |
-
|
| 39 |
-
weight, confidence = extract_weight_from_image(image)
|
| 40 |
-
|
| 41 |
-
# Timestamp
|
| 42 |
ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
|
| 43 |
-
|
| 44 |
-
# Output
|
| 45 |
-
st.markdown("### π
Captured At (IST)")
|
| 46 |
st.info(ist_time)
|
| 47 |
|
| 48 |
-
st.markdown("### πΌοΈ Snapshot")
|
| 49 |
st.image(image, width=400)
|
| 50 |
|
| 51 |
-
st.
|
|
|
|
|
|
|
|
|
|
| 52 |
if confidence > 0:
|
| 53 |
st.success(f"Detected Weight: **{weight}** \nConfidence: `{confidence:.2f}`")
|
| 54 |
else:
|
| 55 |
-
st.error("No weight detected.
|
| 56 |
-
|
| 57 |
-
# (Optional) Send to Salesforce button
|
| 58 |
-
st.markdown("π [Send to Salesforce](#)", unsafe_allow_html=True)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image, UnidentifiedImageError
|
|
|
|
| 3 |
from datetime import datetime
|
| 4 |
import pytz
|
| 5 |
from ocr_engine import extract_weight_from_image
|
| 6 |
|
| 7 |
+
# Streamlit page config
|
| 8 |
st.set_page_config(page_title="βοΈ Auto Weight Logger", layout="centered")
|
| 9 |
st.title("βοΈ Auto Weight Logger")
|
| 10 |
|
| 11 |
+
# Debug: Confirm app starts
|
| 12 |
+
st.write("β
Streamlit app initialized.")
|
| 13 |
+
|
| 14 |
if "camera_key" not in st.session_state:
|
| 15 |
st.session_state["camera_key"] = 0
|
| 16 |
|
| 17 |
+
# Upload or Capture
|
| 18 |
col1, col2 = st.columns(2)
|
| 19 |
with col1:
|
| 20 |
uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
|
|
|
| 36 |
except UnidentifiedImageError:
|
| 37 |
st.error("Invalid camera image.")
|
| 38 |
|
| 39 |
+
# OCR Process
|
| 40 |
if image:
|
| 41 |
+
st.markdown("### π Captured At (IST)")
|
|
|
|
|
|
|
|
|
|
| 42 |
ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
|
|
|
|
|
| 43 |
st.info(ist_time)
|
| 44 |
|
| 45 |
+
st.markdown("### πΌοΈ Snapshot Image")
|
| 46 |
st.image(image, width=400)
|
| 47 |
|
| 48 |
+
with st.spinner("π Detecting weight..."):
|
| 49 |
+
weight, confidence = extract_weight_from_image(image)
|
| 50 |
+
|
| 51 |
+
st.markdown("### βοΈ Captured Weight & Confidence")
|
| 52 |
if confidence > 0:
|
| 53 |
st.success(f"Detected Weight: **{weight}** \nConfidence: `{confidence:.2f}`")
|
| 54 |
else:
|
| 55 |
+
st.error("No weight detected. Please upload a clearer image.")
|
|
|
|
|
|
|
|
|