File size: 1,099 Bytes
0590b95
d55b56b
 
9bbac2d
d55b56b
0590b95
d55b56b
a4391a6
 
 
91bcc4e
 
9bbac2d
 
 
 
 
 
91bcc4e
a4391a6
d55b56b
 
a4391a6
9bbac2d
136c114
a4391a6
f32159a
9bbac2d
a4391a6
 
 
f32159a
 
0590b95
d55b56b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gradio as gr
from PIL import Image
from datetime import datetime
import pytz
from ocr_engine import extract_weight

def process_image(image):
    if image is None:
        return "No image provided", "", None

    try:
        weight = extract_weight(image)

        # Get IST time
        ist = pytz.timezone('Asia/Kolkata')
        now_ist = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S IST")

        return weight, now_ist, image
    except Exception as e:
        return f"Error: {str(e)}", "", None

with gr.Blocks() as demo:
    gr.Markdown("## πŸ“· Auto Weight Logger β€” Hugging Face OCR Edition")
    gr.Markdown("Upload a digital weight image. Auto-detects value & unit (kg or grams).")

    image_input = gr.Image(type="pil", label="πŸ“ Upload or Capture Image")
    detect_btn = gr.Button("πŸš€ Detect Weight")

    weight_out = gr.Textbox(label="Detected Weight")
    time_out = gr.Textbox(label="Captured At (IST)")
    snapshot = gr.Image(label="Snapshot")

    detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])

demo.launch()