logger1 / app.py
Sanjayraju30's picture
Update app.py
a4391a6 verified
raw
history blame
1.05 kB
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 f"{weight} grams", 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. Detects weight using a transformer-based OCR model.")
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()