Sanjayraju30 commited on
Commit
92fb795
Β·
verified Β·
1 Parent(s): 5e000f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -2,25 +2,25 @@ import gradio as gr
2
  from PIL import Image, UnidentifiedImageError
3
  from datetime import datetime
4
  import pytz
5
- from ocr_engine import extract_weight_from_image # Make sure this file exists
6
 
7
  def detect_weight(image: Image.Image):
8
  try:
9
- # Get IST timestamp
10
  ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
11
 
12
- # Perform OCR
13
  weight, confidence = extract_weight_from_image(image)
14
 
15
  if confidence > 0:
16
  result = f"βœ… **Detected Weight:** {weight} \nπŸ“Š **Confidence:** {confidence:.2f} \nπŸ•’ **Captured At (IST):** {ist_time}"
17
  else:
18
  result = "❌ No weight detected. Please upload a clearer image."
 
19
  return image, result
20
  except UnidentifiedImageError:
21
  return None, "❌ Invalid image format."
22
 
23
- # Gradio UI
24
  demo = gr.Interface(
25
  fn=detect_weight,
26
  inputs=gr.Image(type="pil", label="Upload or Capture Image"),
@@ -29,7 +29,7 @@ demo = gr.Interface(
29
  gr.Markdown(label="Result")
30
  ],
31
  title="βš–οΈ Auto Weight Logger",
32
- description="Upload or capture a digital scale snapshot to detect weight automatically.",
33
  allow_flagging="never"
34
  )
35
 
 
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
  def detect_weight(image: Image.Image):
8
  try:
9
+ # Get IST time
10
  ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
11
 
12
+ # OCR extraction
13
  weight, confidence = extract_weight_from_image(image)
14
 
15
  if confidence > 0:
16
  result = f"βœ… **Detected Weight:** {weight} \nπŸ“Š **Confidence:** {confidence:.2f} \nπŸ•’ **Captured At (IST):** {ist_time}"
17
  else:
18
  result = "❌ No weight detected. Please upload a clearer image."
19
+
20
  return image, result
21
  except UnidentifiedImageError:
22
  return None, "❌ Invalid image format."
23
 
 
24
  demo = gr.Interface(
25
  fn=detect_weight,
26
  inputs=gr.Image(type="pil", label="Upload or Capture Image"),
 
29
  gr.Markdown(label="Result")
30
  ],
31
  title="βš–οΈ Auto Weight Logger",
32
+ description="Upload or capture a digital scale image to detect weight automatically.",
33
  allow_flagging="never"
34
  )
35