logger / app.py
Sanjayraju30's picture
Update app.py
91bcc4e verified
raw
history blame
1.09 kB
import gradio as gr
from PIL import Image
from datetime import datetime
from ocr_engine import extract_weight
def process_image(image):
try:
if image is None:
return "No image provided", "No timestamp", None
weight = extract_weight(image)
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return f"{weight} grams", now, image
except Exception as e:
return f"Error: {str(e)}", "Error", None
with gr.Blocks() as demo:
gr.Markdown("## πŸ“· Auto Weight Logger β€” OCR-Based Smart Scale Reader")
gr.Markdown("Upload a photo of a digital scale. The app will detect and log the weight.")
image_input = gr.Image(type="pil", label="πŸ“ Upload or Capture Digital Scale 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 Preview")
detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])
demo.launch()