Sanjayraju30 commited on
Commit
91bcc4e
Β·
verified Β·
1 Parent(s): 1cb8b90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -4,25 +4,26 @@ from datetime import datetime
4
  from ocr_engine import extract_weight
5
 
6
  def process_image(image):
7
- if image is None:
8
- return "No image provided", None, None
9
- weight = extract_weight(image)
10
- now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
11
- return f"{weight} grams", now, image
 
 
 
12
 
13
  with gr.Blocks() as demo:
14
  gr.Markdown("## πŸ“· Auto Weight Logger β€” OCR-Based Smart Scale Reader")
15
- gr.Markdown("Upload or capture a digital scale snapshot. This app detects the weight using OCR.")
16
 
17
- image_input = gr.Image(type="pil", label="πŸ“ Upload or Capture Image")
18
 
19
  detect_btn = gr.Button("πŸš€ Detect Weight")
20
 
21
- with gr.Row():
22
- weight_out = gr.Textbox(label="Detected Weight")
23
- time_out = gr.Textbox(label="Captured At (IST)")
24
-
25
- snapshot = gr.Image(label="Snapshot")
26
 
27
  detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])
28
 
 
4
  from ocr_engine import extract_weight
5
 
6
  def process_image(image):
7
+ try:
8
+ if image is None:
9
+ return "No image provided", "No timestamp", None
10
+ weight = extract_weight(image)
11
+ now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
12
+ return f"{weight} grams", now, image
13
+ except Exception as e:
14
+ return f"Error: {str(e)}", "Error", None
15
 
16
  with gr.Blocks() as demo:
17
  gr.Markdown("## πŸ“· Auto Weight Logger β€” OCR-Based Smart Scale Reader")
18
+ gr.Markdown("Upload a photo of a digital scale. The app will detect and log the weight.")
19
 
20
+ image_input = gr.Image(type="pil", label="πŸ“ Upload or Capture Digital Scale Image")
21
 
22
  detect_btn = gr.Button("πŸš€ Detect Weight")
23
 
24
+ weight_out = gr.Textbox(label="πŸ“¦ Detected Weight")
25
+ time_out = gr.Textbox(label="⏱️ Captured At (IST)")
26
+ snapshot = gr.Image(label="πŸ–ΌοΈ Snapshot Preview")
 
 
27
 
28
  detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])
29