Spaces:
Build error
Build error
File size: 1,211 Bytes
9bbe87e 1279f5b 92fb795 812afe6 1279f5b 788bf64 1279f5b 92fb795 1279f5b 9bbe87e 1279f5b 0112378 1279f5b 0112378 1279f5b 9bbe87e 1279f5b 9bbe87e 1279f5b 9bbe87e 1279f5b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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()
|