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, gr.update(visible=True) try: weight = extract_weight(image) ist = pytz.timezone('Asia/Kolkata') timestamp = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S IST") if not weight or "No valid" in weight: return "❌ Unable to detect. Try again with clearer image.", "", image, gr.update(visible=True) return weight, timestamp, image, gr.update(visible=False) except Exception as e: return f"Error: {str(e)}", "", None, gr.update(visible=True) with gr.Blocks(css=".gr-button {background-color: #2e7d32 !important; color: white !important;}") as demo: gr.Markdown("""
Upload or capture a digital weight image. Detects weight using OCR.
Tip: Ensure the image is clear and not blurry.
Developed by Shalu • Hugging Face OCR ⚡