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()