Sanjayraju30 commited on
Commit
1aeda96
Β·
verified Β·
1 Parent(s): c758305

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +15 -15
src/streamlit_app.py CHANGED
@@ -25,26 +25,26 @@ def extract_weight_text(image):
25
  return None
26
 
27
  st.set_page_config(page_title="Auto Weight Logger", layout="centered")
28
- st.title("πŸ“¦ Auto Weight Logger (Streamlit)")
29
- st.write("Upload or capture an image of a digital weight display to extract weight.")
30
 
31
- uploaded_img = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
32
- camera_img = st.camera_input("Or click an image")
33
 
34
- input_img = uploaded_img or camera_img
35
 
36
- if input_img is not None:
37
- image = Image.open(input_img)
38
- st.image(image, caption="Original Image", use_column_width=True)
39
 
40
- pre_img = preprocess_image(image)
41
- st.image(pre_img, caption="Preprocessed Image", use_column_width=True)
42
 
43
- weight = extract_weight_text(pre_img)
44
 
45
  if weight:
46
- ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
47
- st.success(f"βœ… Weight Detected: **{weight} kg**")
48
- st.info(f"πŸ•’ Captured At (IST): {ist_time}")
49
  else:
50
- st.error("❌ Could not detect weight. Please try with a clearer image.")
 
25
  return None
26
 
27
  st.set_page_config(page_title="Auto Weight Logger", layout="centered")
28
+ st.title("πŸ“¦ Auto Weight Logger")
29
+ st.write("Upload or click image of weight display. App will read the weight.")
30
 
31
+ uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
32
+ camera_image = st.camera_input("Or Capture Image")
33
 
34
+ input_image = uploaded_file or camera_image
35
 
36
+ if input_image:
37
+ image = Image.open(input_image)
38
+ st.image(image, caption="Original", use_column_width=True)
39
 
40
+ processed = preprocess_image(image)
41
+ st.image(processed, caption="Processed", use_column_width=True)
42
 
43
+ weight = extract_weight_text(processed)
44
 
45
  if weight:
46
+ time_now = datetime.now(pytz.timezone('Asia/Kolkata')).strftime('%Y-%m-%d %H:%M:%S')
47
+ st.success(f"βœ… Weight Detected: {weight} kg")
48
+ st.info(f"⏱️ Captured At: {time_now}")
49
  else:
50
+ st.error("❌ Weight not detected. Try clearer image.")