File size: 1,205 Bytes
9bbe87e
4f5f0dd
 
 
92fb795
812afe6
9bbe87e
4f5f0dd
92fb795
9bbe87e
4f5f0dd
92fb795
788bf64
 
9bbe87e
9aa3367
9bbe87e
 
92fb795
9bbe87e
 
 
 
 
 
 
 
 
 
 
9aa3367
92fb795
9bbe87e
 
 
 
 
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
import gradio as gr
from PIL import Image, UnidentifiedImageError
from datetime import datetime
import pytz
from ocr_engine import extract_weight_from_image

def detect_weight(image: Image.Image):
    try:
        # Get IST time
        ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")

        # OCR extraction
        weight, confidence = extract_weight_from_image(image)

        if confidence > 0:
            result = f"βœ… **Detected Weight:** {weight}  \nπŸ“Š **Confidence:** {confidence:.2f}  \nπŸ•’ **Captured At (IST):** {ist_time}"
        else:
            result = "❌ No weight detected. Please upload a clearer image."

        return image, result
    except UnidentifiedImageError:
        return None, "❌ Invalid image format."

demo = gr.Interface(
    fn=detect_weight,
    inputs=gr.Image(type="pil", label="Upload or Capture Image"),
    outputs=[
        gr.Image(type="pil", label="Snapshot"),
        gr.Markdown(label="Result")
    ],
    title="βš–οΈ Auto Weight Logger",
    description="Upload or capture a digital scale image to detect weight automatically.",
    allow_flagging="never"
)

if __name__ == "__main__":
    demo.launch()