Spaces:
Build error
Build error
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() | |