File size: 1,444 Bytes
aebbc1f
 
 
53ad608
 
aebbc1f
4fd2f10
53ad608
 
aebbc1f
 
53ad608
aebbc1f
4fd2f10
 
 
aebbc1f
4fd2f10
 
 
aebbc1f
4fd2f10
 
 
aebbc1f
4fd2f10
 
aebbc1f
 
4fd2f10
 
 
 
 
 
 
 
 
 
 
 
 
aebbc1f
 
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
42
43
44
45
46
47
import os
os.environ['PADDLEX_HOME'] = '/tmp/.paddlex'  # Fix for Hugging Face permission error

from paddleocr import PaddleOCR
from PIL import Image
import streamlit as st
import numpy as np
import re

# Initialize PaddleOCR model
ocr = PaddleOCR(use_angle_cls=True, lang='en')  # Enable angle classification

# Streamlit page setup
st.set_page_config(page_title="Auto Weight Logger", layout="centered")
st.title("πŸ“· Auto Weight Logger")

# File uploader
uploaded_file = st.file_uploader("Upload an image of the weight display", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    # Display uploaded image
    image = Image.open(uploaded_file).convert("RGB")
    st.image(image, caption="Uploaded Image", use_column_width=True)

    # Convert image to numpy array for OCR
    img_array = np.array(image)

    # OCR Detection
    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
            if weight != "Not detected":
                break

        st.markdown(f"### βœ… Weight: **{weight} kg** (Confidence: {confidence:.2%})")