Spaces:
Sleeping
Sleeping
File size: 1,597 Bytes
53ad608 69bb60f 53ad608 1aeda96 53ad608 1aeda96 53ad608 1aeda96 53ad608 1aeda96 53ad608 1aeda96 53ad608 1aeda96 53ad608 1aeda96 53ad608 1aeda96 |
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 |
import streamlit as st
import numpy as np
import cv2
from paddleocr import PaddleOCR
from PIL import Image
import re
from datetime import datetime
import pytz
ocr = PaddleOCR(use_angle_cls=True, lang='en')
def preprocess_image(image):
img = np.array(image.convert("RGB"))
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
_, thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
return Image.fromarray(thresh)
def extract_weight_text(image):
results = ocr.ocr(np.array(image), cls=True)
for line in results[0]:
text = line[1][0]
match = re.search(r"\d+\.\d+", text)
if match:
return match.group()
return None
st.set_page_config(page_title="Auto Weight Logger", layout="centered")
st.title("π¦ Auto Weight Logger")
st.write("Upload or click image of weight display. App will read the weight.")
uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
camera_image = st.camera_input("Or Capture Image")
input_image = uploaded_file or camera_image
if input_image:
image = Image.open(input_image)
st.image(image, caption="Original", use_column_width=True)
processed = preprocess_image(image)
st.image(processed, caption="Processed", use_column_width=True)
weight = extract_weight_text(processed)
if weight:
time_now = datetime.now(pytz.timezone('Asia/Kolkata')).strftime('%Y-%m-%d %H:%M:%S')
st.success(f"β
Weight Detected: {weight} kg")
st.info(f"β±οΈ Captured At: {time_now}")
else:
st.error("β Weight not detected. Try clearer image.")
|