Sanjayraju30 commited on
Commit
a4391a6
Β·
verified Β·
1 Parent(s): 513f893

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -4,26 +4,26 @@ from datetime import datetime
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
 
 
4
  from ocr_engine import extract_weight
5
 
6
  def process_image(image):
7
+ if image is None:
8
+ return "No image provided", "", None
9
+
10
  try:
 
 
11
  weight = extract_weight(image)
12
+ timestamp = datetime.now().astimezone().strftime("%Y-%m-%d %H:%M:%S %Z")
13
+ return f"{weight} grams", timestamp, image
14
  except Exception as e:
15
+ return f"Error: {str(e)}", "", None
16
 
17
  with gr.Blocks() as demo:
18
+ gr.Markdown("## πŸ“· Auto Weight Logger β€” Hugging Face OCR Edition")
19
+ gr.Markdown("Upload a digital scale image. Detects weight using a transformer-based OCR model.")
20
 
21
+ image_input = gr.Image(type="pil", label="πŸ“ Upload or Capture Image")
22
 
23
  detect_btn = gr.Button("πŸš€ Detect Weight")
24
+ weight_out = gr.Textbox(label="Detected Weight")
25
+ time_out = gr.Textbox(label="Captured At (IST)")
26
+ snapshot = gr.Image(label="Snapshot")
 
27
 
28
  detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])
29