Autoweight / app.py
Sanjayraju30's picture
Update app.py
1279f5b verified
import gradio as gr
from PIL import Image
from datetime import datetime
import pytz
from ocr_engine import extract_weight_from_image
def process_image(img):
# Convert image to RGB in case it's RGBA or grayscale
img = img.convert("RGB")
# Get IST timestamp
ist = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
# Run OCR
weight, confidence = extract_weight_from_image(img)
# Format output
result = f"πŸ“… Captured At (IST): {ist}\n"
if confidence > 0:
result += f"βš–οΈ Detected Weight: **{weight}**\n"
result += f"βœ… Confidence: `{confidence:.2f}`"
else:
result += "❌ No weight detected. Try a clearer image."
return img, result
# Gradio UI
demo = gr.Interface(
fn=process_image,
inputs=gr.Image(type="pil", label="Upload or Capture Image"),
outputs=[
gr.Image(type="pil", label="Snapshot"),
gr.Markdown(label="Weight Result")
],
title="βš–οΈ Auto Weight Logger (PaddleOCR)",
description="Upload or capture an image of a weighing scale. This app uses PaddleOCR to detect the weight value.",
allow_flagging="never"
)
if __name__ == "__main__":
demo.launch()