import gradio as gr from datetime import datetime import pytz from ocr_engine import extract_weight_from_image def process_image(img): if img is None: return "No image uploaded", None, None ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%d-%m-%Y %I:%M:%S %p") weight, _ = extract_weight_from_image(img) # Ignore confidence in UI return weight, ist_time, img with gr.Blocks(title="⚖️ Auto Weight Logger") as demo: gr.Markdown("# ⚖️ Auto Weight Logger") gr.Markdown("Upload or capture an image of a **digital scale display** to auto-detect the weight in kilograms.") with gr.Row(): image_input = gr.Image(type="pil", label="📷 Upload or Capture Image") output_weight = gr.Textbox(label="⚖️ Detected Weight") with gr.Row(): timestamp = gr.Textbox(label="🕒 Captured At (IST)") snapshot = gr.Image(label="📸 Snapshot Image") submit = gr.Button("🔍 Detect Weight") submit.click(process_image, inputs=image_input, outputs=[output_weight, timestamp, snapshot]) demo.launch()