Update src/streamlit_app.py
Browse files- src/streamlit_app.py +13 -27
src/streamlit_app.py
CHANGED
@@ -1,30 +1,16 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
Option 2: Upload image from local machine
|
17 |
-
if image_file is None:
|
18 |
-
image_file = st.file_uploader("Or upload an image", type=["jpg", "jpeg", "png"])
|
19 |
-
|
20 |
-
if image_file is not None:
|
21 |
-
image = Image.open(image_file)
|
22 |
-
st.image(image, caption="Uploaded Image", use_column_width=True)
|
23 |
-
|
24 |
-
python
|
25 |
-
Copy
|
26 |
-
Edit
|
27 |
-
with st.spinner("🔍 Extracting weight..."):
|
28 |
-
result = extract_weight_from_image(image)
|
29 |
-
|
30 |
-
st.success(f"✅ Detected Weight: {result} g")
|
|
|
1 |
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
import tempfile
|
4 |
+
import base64
|
5 |
+
from ocr_engine import extract_weight
|
6 |
|
7 |
+
st.title("Auto Weight Logger")
|
8 |
+
img_data = st.camera_input("Capture weight display")
|
9 |
|
10 |
+
if img_data:
|
11 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as f:
|
12 |
+
f.write(img_data.getvalue())
|
13 |
+
f.flush()
|
14 |
+
weight = extract_weight(f.name)
|
15 |
+
st.image(f.name, caption="Snapshot")
|
16 |
+
st.success(f"Detected Weight: {weight} g")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|