Sanjayraju30 commited on
Commit
77bb0dd
Β·
verified Β·
1 Parent(s): a4b646d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -9,25 +9,32 @@ def process_image(image):
9
  return "No image provided", "", None
10
  try:
11
  weight = extract_weight(image)
12
-
13
  ist = pytz.timezone('Asia/Kolkata')
14
- now_ist = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S IST")
15
-
16
- return weight, now_ist, image
17
  except Exception as e:
18
  return f"Error: {str(e)}", "", None
19
 
20
- with gr.Blocks() as demo:
21
- gr.Markdown("## πŸ“· Auto Weight Logger β€” Hugging Face OCR Edition")
22
- gr.Markdown("Upload a digital weight image. AI detects numeric value and unit (kg or grams).")
 
 
 
 
 
 
 
 
23
 
24
- image_input = gr.Image(type="pil", label="πŸ“ Upload or Capture Image")
25
- detect_btn = gr.Button("πŸš€ Detect Weight")
 
26
 
27
- weight_out = gr.Textbox(label="Detected Weight")
28
- time_out = gr.Textbox(label="Captured At (IST)")
29
- snapshot = gr.Image(label="Snapshot")
30
 
31
  detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])
32
 
33
- demo.launch()
 
 
 
9
  return "No image provided", "", None
10
  try:
11
  weight = extract_weight(image)
 
12
  ist = pytz.timezone('Asia/Kolkata')
13
+ timestamp = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S IST")
14
+ return weight, timestamp, image
 
15
  except Exception as e:
16
  return f"Error: {str(e)}", "", None
17
 
18
+ with gr.Blocks(css=".gr-button {background-color: #2e7d32 !important; color: white !important;}") as demo:
19
+ gr.Markdown("""
20
+ <h1 style='text-align: center; color: #2e7d32;'>πŸ“· Auto Weight Logger</h1>
21
+ <p style='text-align: center;'>AI-powered OCR tool to detect weights (kg or grams) from digital balance display images.</p>
22
+ <hr style='border: 1px solid #ddd;'/>
23
+ """)
24
+
25
+ with gr.Row():
26
+ image_input = gr.Image(type="pil", label="πŸ“ Upload or Capture Image", elem_id="img_upload")
27
+
28
+ detect_btn = gr.Button("πŸš€ Detect Weight", elem_id="detect_btn")
29
 
30
+ with gr.Row():
31
+ weight_out = gr.Textbox(label="πŸ“¦ Detected Weight", placeholder="e.g., 72.4 kg", show_copy_button=True)
32
+ time_out = gr.Textbox(label="πŸ•’ Captured At (IST)", placeholder="e.g., 2025-06-30 14:32:10")
33
 
34
+ snapshot = gr.Image(label="πŸ“Έ Snapshot Preview")
 
 
35
 
36
  detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])
37
 
38
+ gr.Markdown("""
39
+ <br><p style='text-align: center; color: gray;'>Developed by Shalu | Powered by Hugging Face OCR πŸš€</p>
40
+ """)