Spaces:
Build error
Build error
File size: 1,719 Bytes
4f5f0dd 812afe6 788bf64 4f5f0dd 788bf64 4f5f0dd 788bf64 4f5f0dd a51774c 4f5f0dd 788bf64 4f5f0dd 788bf64 4f5f0dd 788bf64 4f5f0dd 788bf64 4f5f0dd 788bf64 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import streamlit as st
from PIL import Image, UnidentifiedImageError
from datetime import datetime
import pytz
from ocr_engine import extract_weight_from_image
# Streamlit page config
st.set_page_config(page_title="βοΈ Auto Weight Logger", layout="centered")
st.title("βοΈ Auto Weight Logger")
# Debug: Confirm app starts
st.write("β
Streamlit app initialized.")
if "camera_key" not in st.session_state:
st.session_state["camera_key"] = 0
# Upload or Capture
col1, col2 = st.columns(2)
with col1:
uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
with col2:
if st.button("πΈ Retake Photo"):
st.session_state["camera_key"] += 1
camera_image = st.camera_input("Capture Image", key=st.session_state["camera_key"])
# Load image
image = None
if uploaded_file:
try:
image = Image.open(uploaded_file)
except UnidentifiedImageError:
st.error("Invalid image format.")
elif camera_image:
try:
image = Image.open(camera_image)
except UnidentifiedImageError:
st.error("Invalid camera image.")
# OCR Process
if image:
st.markdown("### π Captured At (IST)")
ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
st.info(ist_time)
st.markdown("### πΌοΈ Snapshot Image")
st.image(image, width=400)
with st.spinner("π Detecting weight..."):
weight, confidence = extract_weight_from_image(image)
st.markdown("### βοΈ Captured Weight & Confidence")
if confidence > 0:
st.success(f"Detected Weight: **{weight}** \nConfidence: `{confidence:.2f}`")
else:
st.error("No weight detected. Please upload a clearer image.")
|