Sanjayraju30 commited on
Commit
69bb60f
·
verified ·
1 Parent(s): f3297d5

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +1 -7
src/streamlit_app.py CHANGED
@@ -7,17 +7,14 @@ import re
7
  from datetime import datetime
8
  import pytz
9
 
10
- # Load OCR Model
11
- ocr = PaddleOCR(use_angle_cls=True, lang='en') # do not reinstall paddleocr here
12
 
13
- # Preprocess image: grayscale + threshold
14
  def preprocess_image(image):
15
  img = np.array(image.convert("RGB"))
16
  gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
17
  _, thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
18
  return Image.fromarray(thresh)
19
 
20
- # Extract weight using regex
21
  def extract_weight_text(image):
22
  results = ocr.ocr(np.array(image), cls=True)
23
  for line in results[0]:
@@ -27,7 +24,6 @@ def extract_weight_text(image):
27
  return match.group()
28
  return None
29
 
30
- # Streamlit UI
31
  st.set_page_config(page_title="Auto Weight Logger", layout="centered")
32
  st.title("📦 Auto Weight Logger (Streamlit)")
33
  st.write("Upload or capture an image of a digital weight display to extract weight.")
@@ -41,11 +37,9 @@ if input_img is not None:
41
  image = Image.open(input_img)
42
  st.image(image, caption="Original Image", use_column_width=True)
43
 
44
- # Preprocess and show preprocessed image
45
  pre_img = preprocess_image(image)
46
  st.image(pre_img, caption="Preprocessed Image", use_column_width=True)
47
 
48
- # Detect weight
49
  weight = extract_weight_text(pre_img)
50
 
51
  if weight:
 
7
  from datetime import datetime
8
  import pytz
9
 
10
+ ocr = PaddleOCR(use_angle_cls=True, lang='en')
 
11
 
 
12
  def preprocess_image(image):
13
  img = np.array(image.convert("RGB"))
14
  gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
15
  _, thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
16
  return Image.fromarray(thresh)
17
 
 
18
  def extract_weight_text(image):
19
  results = ocr.ocr(np.array(image), cls=True)
20
  for line in results[0]:
 
24
  return match.group()
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.")
 
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: