File size: 1,212 Bytes
53ad608
 
 
4fd2f10
53ad608
 
4fd2f10
69bb60f
53ad608
4fd2f10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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%})")