Sanjayraju30 commited on
Commit
216f81d
Β·
verified Β·
1 Parent(s): 5e8a3f0

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +13 -27
src/streamlit_app.py CHANGED
@@ -1,30 +1,16 @@
1
  import streamlit as st
2
- import os
3
- from PIL import Image
4
- from ocr_engine import extract_weight_from_image
 
5
 
6
- Install Tesseract runtime in Hugging Face Space
7
- os.system("apt update && apt install -y tesseract-ocr")
8
 
9
- st.set_page_config(page_title="βš–οΈ Auto Weight Logger", layout="centered")
10
- st.title("πŸ“· Auto Weight Logger")
11
- st.write("Capture the weight display using your camera or upload an image")
12
-
13
- Option 1: Capture image from webcam
14
- image_file = st.camera_input("Take a photo")
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")