import streamlit as st from paddleocr import PaddleOCR from PIL import Image import numpy as np import re # Initialize OCR ocr = PaddleOCR(use_angle_cls=True, lang='en') st.set_page_config(page_title="Auto Weight Logger", layout="centered") st.title("📷 Auto Weight Logger") # Upload image uploaded_file = st.file_uploader("Upload an image of the weight display", type=["jpg", "jpeg", "png"]) if uploaded_file is not None: # Load image using PIL (no OpenCV) image = Image.open(uploaded_file).convert("RGB") st.image(image, caption="Uploaded Image", use_column_width=True) # Convert PIL image to numpy array img_array = np.array(image) # Run OCR with st.spinner("Detecting weight..."): result = ocr.ocr(img_array, cls=True) weight = "Not detected" confidence = 0.0 for line in result[0]: for word_info in line: text, conf = word_info[1] match = re.search(r'\d+\.\d+|\d+', text) if match: weight = match.group() confidence = conf break st.markdown(f"### ✅ Weight: **{weight} kg** (Confidence: {confidence:.2%})")