logger2 / app.py
Sanjayraju30's picture
Update app.py
f32159a verified
raw
history blame
967 Bytes
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, None
weight = extract_weight(image)
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return f"{weight} grams", now, image
with gr.Blocks() as demo:
gr.Markdown("## πŸ“· Auto Weight Logger β€” OCR-Based Smart Scale Reader")
gr.Markdown("Upload or capture a digital scale snapshot. This app detects the weight using OCR.")
image_input = gr.Image(type="pil", label="πŸ“ Upload or Capture Image")
detect_btn = gr.Button("πŸš€ Detect Weight")
with gr.Row():
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()