Sanjayraju30 commited on
Commit
788bf64
Β·
verified Β·
1 Parent(s): c824cdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
app.py CHANGED
@@ -1,17 +1,20 @@
1
  import streamlit as st
2
  from PIL import Image, UnidentifiedImageError
3
- import io
4
  from datetime import datetime
5
  import pytz
6
  from ocr_engine import extract_weight_from_image
7
 
 
8
  st.set_page_config(page_title="βš–οΈ Auto Weight Logger", layout="centered")
9
  st.title("βš–οΈ Auto Weight Logger")
10
 
 
 
 
11
  if "camera_key" not in st.session_state:
12
  st.session_state["camera_key"] = 0
13
 
14
- # UI: Upload or Capture Image
15
  col1, col2 = st.columns(2)
16
  with col1:
17
  uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
@@ -33,26 +36,20 @@ elif camera_image:
33
  except UnidentifiedImageError:
34
  st.error("Invalid camera image.")
35
 
36
- # Process image
37
  if image:
38
- with st.spinner("Detecting weight..."):
39
- weight, confidence = extract_weight_from_image(image)
40
-
41
- # Timestamp
42
  ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
43
-
44
- # Output
45
- st.markdown("### πŸ“… Captured At (IST)")
46
  st.info(ist_time)
47
 
48
- st.markdown("### πŸ–ΌοΈ Snapshot")
49
  st.image(image, width=400)
50
 
51
- st.markdown("### βš–οΈ Detected Weight")
 
 
 
52
  if confidence > 0:
53
  st.success(f"Detected Weight: **{weight}** \nConfidence: `{confidence:.2f}`")
54
  else:
55
- st.error("No weight detected. Try with a clearer image.")
56
-
57
- # (Optional) Send to Salesforce button
58
- st.markdown("πŸ”— [Send to Salesforce](#)", unsafe_allow_html=True)
 
1
  import streamlit as st
2
  from PIL import Image, UnidentifiedImageError
 
3
  from datetime import datetime
4
  import pytz
5
  from ocr_engine import extract_weight_from_image
6
 
7
+ # Streamlit page config
8
  st.set_page_config(page_title="βš–οΈ Auto Weight Logger", layout="centered")
9
  st.title("βš–οΈ Auto Weight Logger")
10
 
11
+ # Debug: Confirm app starts
12
+ st.write("βœ… Streamlit app initialized.")
13
+
14
  if "camera_key" not in st.session_state:
15
  st.session_state["camera_key"] = 0
16
 
17
+ # Upload or Capture
18
  col1, col2 = st.columns(2)
19
  with col1:
20
  uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
 
36
  except UnidentifiedImageError:
37
  st.error("Invalid camera image.")
38
 
39
+ # OCR Process
40
  if image:
41
+ st.markdown("### πŸ•’ Captured At (IST)")
 
 
 
42
  ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
 
 
 
43
  st.info(ist_time)
44
 
45
+ st.markdown("### πŸ–ΌοΈ Snapshot Image")
46
  st.image(image, width=400)
47
 
48
+ with st.spinner("πŸ” Detecting weight..."):
49
+ weight, confidence = extract_weight_from_image(image)
50
+
51
+ st.markdown("### βš–οΈ Captured Weight & Confidence")
52
  if confidence > 0:
53
  st.success(f"Detected Weight: **{weight}** \nConfidence: `{confidence:.2f}`")
54
  else:
55
+ st.error("No weight detected. Please upload a clearer image.")