Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +14 -8
src/streamlit_app.py
CHANGED
@@ -1,28 +1,32 @@
|
|
1 |
-
import
|
|
|
|
|
2 |
from paddleocr import PaddleOCR
|
3 |
from PIL import Image
|
|
|
4 |
import numpy as np
|
5 |
import re
|
6 |
|
7 |
-
# Initialize
|
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 |
-
#
|
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 |
-
#
|
18 |
image = Image.open(uploaded_file).convert("RGB")
|
19 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
20 |
|
21 |
-
# Convert
|
22 |
img_array = np.array(image)
|
23 |
|
24 |
-
#
|
25 |
-
with st.spinner("Detecting weight..."):
|
26 |
result = ocr.ocr(img_array, cls=True)
|
27 |
|
28 |
weight = "Not detected"
|
@@ -36,5 +40,7 @@ if uploaded_file is not None:
|
|
36 |
weight = match.group()
|
37 |
confidence = conf
|
38 |
break
|
|
|
|
|
39 |
|
40 |
st.markdown(f"### β
Weight: **{weight} kg** (Confidence: {confidence:.2%})")
|
|
|
1 |
+
import os
|
2 |
+
os.environ['PADDLEX_HOME'] = '/tmp/.paddlex' # Fix for Hugging Face permission error
|
3 |
+
|
4 |
from paddleocr import PaddleOCR
|
5 |
from PIL import Image
|
6 |
+
import streamlit as st
|
7 |
import numpy as np
|
8 |
import re
|
9 |
|
10 |
+
# Initialize PaddleOCR model
|
11 |
+
ocr = PaddleOCR(use_angle_cls=True, lang='en') # Enable angle classification
|
12 |
|
13 |
+
# Streamlit page setup
|
14 |
st.set_page_config(page_title="Auto Weight Logger", layout="centered")
|
15 |
st.title("π· Auto Weight Logger")
|
16 |
|
17 |
+
# File uploader
|
18 |
uploaded_file = st.file_uploader("Upload an image of the weight display", type=["jpg", "jpeg", "png"])
|
19 |
|
20 |
if uploaded_file is not None:
|
21 |
+
# Display uploaded image
|
22 |
image = Image.open(uploaded_file).convert("RGB")
|
23 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
24 |
|
25 |
+
# Convert image to numpy array for OCR
|
26 |
img_array = np.array(image)
|
27 |
|
28 |
+
# OCR Detection
|
29 |
+
with st.spinner("π Detecting weight..."):
|
30 |
result = ocr.ocr(img_array, cls=True)
|
31 |
|
32 |
weight = "Not detected"
|
|
|
40 |
weight = match.group()
|
41 |
confidence = conf
|
42 |
break
|
43 |
+
if weight != "Not detected":
|
44 |
+
break
|
45 |
|
46 |
st.markdown(f"### β
Weight: **{weight} kg** (Confidence: {confidence:.2%})")
|