import gradio as gr from PIL import Image from datetime import datetime from ocr_engine import extract_weight def process_image(image): if image is None: return "No image provided", "", None try: weight = extract_weight(image) timestamp = datetime.now().astimezone().strftime("%Y-%m-%d %H:%M:%S %Z") return weight, timestamp, 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 scale image. This app detects the weight (kg or g) using AI.") 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()