Sanjayraju30 commited on
Commit
9aa3367
Β·
verified Β·
1 Parent(s): accf274

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -2,7 +2,7 @@ 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
6
 
7
  def detect_weight(image: Image.Image):
8
  try:
@@ -13,7 +13,7 @@ def detect_weight(image: Image.Image):
13
  weight, confidence = extract_weight_from_image(image)
14
 
15
  if confidence > 0:
16
- result = f"βœ… **Detected Weight:** {weight}\n\nπŸ“Š **Confidence:** {confidence:.2f}\n\nπŸ•’ **Captured At (IST):** {ist_time}"
17
  else:
18
  result = "❌ No weight detected. Please upload a clearer image."
19
  return image, result
@@ -21,9 +21,6 @@ def detect_weight(image: Image.Image):
21
  return None, "❌ Invalid image format."
22
 
23
  # Gradio UI
24
- title = "βš–οΈ Auto Weight Logger"
25
- description = "Upload or capture an image of a digital weighing scale to automatically extract the weight using OCR."
26
-
27
  demo = gr.Interface(
28
  fn=detect_weight,
29
  inputs=gr.Image(type="pil", label="Upload or Capture Image"),
@@ -31,8 +28,8 @@ demo = gr.Interface(
31
  gr.Image(type="pil", label="Snapshot"),
32
  gr.Markdown(label="Result")
33
  ],
34
- title=title,
35
- description=description,
36
  allow_flagging="never"
37
  )
38
 
 
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:
 
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
 
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"),
 
28
  gr.Image(type="pil", label="Snapshot"),
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