Sanjayraju30 commited on
Commit
9bbac2d
Β·
verified Β·
1 Parent(s): d22d28e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from PIL import Image
3
  from datetime import datetime
 
4
  from ocr_engine import extract_weight
5
 
6
  def process_image(image):
@@ -9,18 +10,22 @@ def process_image(image):
9
 
10
  try:
11
  weight = extract_weight(image)
12
- timestamp = datetime.now().astimezone().strftime("%Y-%m-%d %H:%M:%S %Z")
13
- return weight, 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 photo of a digital scale. The app auto-detects weight (kg or grams).")
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")
 
1
  import gradio as gr
2
  from PIL import Image
3
  from datetime import datetime
4
+ import pytz
5
  from ocr_engine import extract_weight
6
 
7
  def process_image(image):
 
10
 
11
  try:
12
  weight = extract_weight(image)
13
+
14
+ # Get IST time
15
+ ist = pytz.timezone('Asia/Kolkata')
16
+ now_ist = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S IST")
17
+
18
+ return weight, now_ist, image
19
  except Exception as e:
20
  return f"Error: {str(e)}", "", None
21
 
22
  with gr.Blocks() as demo:
23
  gr.Markdown("## πŸ“· Auto Weight Logger β€” Hugging Face OCR Edition")
24
+ gr.Markdown("Upload a digital weight image. Auto-detects value & unit (kg or grams).")
25
 
26
  image_input = gr.Image(type="pil", label="πŸ“ Upload or Capture Image")
 
27
  detect_btn = gr.Button("πŸš€ Detect Weight")
28
+
29
  weight_out = gr.Textbox(label="Detected Weight")
30
  time_out = gr.Textbox(label="Captured At (IST)")
31
  snapshot = gr.Image(label="Snapshot")