Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +33 -34
src/streamlit_app.py
CHANGED
@@ -1,41 +1,40 @@
|
|
1 |
import streamlit as st
|
2 |
-
import numpy as np
|
3 |
-
import cv2
|
4 |
from paddleocr import PaddleOCR
|
5 |
from PIL import Image
|
|
|
6 |
import re
|
7 |
|
|
|
8 |
ocr = PaddleOCR(use_angle_cls=True, lang='en')
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
st.
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
st.error("β Weight not detected.")
|
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
from paddleocr import PaddleOCR
|
3 |
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
import re
|
6 |
|
7 |
+
# Initialize OCR
|
8 |
ocr = PaddleOCR(use_angle_cls=True, lang='en')
|
9 |
|
10 |
+
st.set_page_config(page_title="Auto Weight Logger", layout="centered")
|
11 |
+
st.title("π· Auto Weight Logger")
|
12 |
+
|
13 |
+
# Upload image
|
14 |
+
uploaded_file = st.file_uploader("Upload an image of the weight display", type=["jpg", "jpeg", "png"])
|
15 |
+
|
16 |
+
if uploaded_file is not None:
|
17 |
+
# Load image using PIL (no OpenCV)
|
18 |
+
image = Image.open(uploaded_file).convert("RGB")
|
19 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
20 |
+
|
21 |
+
# Convert PIL image to numpy array
|
22 |
+
img_array = np.array(image)
|
23 |
+
|
24 |
+
# Run OCR
|
25 |
+
with st.spinner("Detecting weight..."):
|
26 |
+
result = ocr.ocr(img_array, cls=True)
|
27 |
+
|
28 |
+
weight = "Not detected"
|
29 |
+
confidence = 0.0
|
30 |
+
|
31 |
+
for line in result[0]:
|
32 |
+
for word_info in line:
|
33 |
+
text, conf = word_info[1]
|
34 |
+
match = re.search(r'\d+\.\d+|\d+', text)
|
35 |
+
if match:
|
36 |
+
weight = match.group()
|
37 |
+
confidence = conf
|
38 |
+
break
|
39 |
+
|
40 |
+
st.markdown(f"### β
Weight: **{weight} kg** (Confidence: {confidence:.2%})")
|
|