File size: 1,367 Bytes
a481416
 
 
 
 
 
 
 
 
6a56695
a481416
2883a04
 
a481416
6a56695
2883a04
 
 
 
 
 
 
a481416
2883a04
a481416
2883a04
 
a481416
4f9e76a
2883a04
6a56695
8c50e18
4f9e76a
 
6c9a667
a481416
4f9e76a
 
a481416
 
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
import gradio as gr
from datetime import datetime
import pytz
from ocr_engine import extract_weight_from_image

def process_image(img):
    if img is None:
        return "No image uploaded", None, None

    # Get IST time
    ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%d-%m-%Y %I:%M:%S %p")
    
    # Run OCR
    weight, confidence = extract_weight_from_image(img)

    # Format output with "kg"
    if weight.replace('.', '', 1).isdigit():
        formatted_weight = f"{weight} kg (Confidence: {confidence}%)"
    else:
        formatted_weight = f"{weight} (Confidence: {confidence}%)"

    return formatted_weight, ist_time, img

# Gradio UI
with gr.Blocks(title="โš–๏ธ Auto Weight Logger") as demo:
    gr.Markdown("# โš–๏ธ Auto Weight Logger")
    gr.Markdown("Upload or capture an image of a **digital scale display**. It will auto-detect the weight in kg.")

    with gr.Row():
        image_input = gr.Image(type="pil", label="๐Ÿ“ท Upload or Capture Image")
        output_weight = gr.Textbox(label="โš–๏ธ Detected Weight (in kg)")

    with gr.Row():
        timestamp = gr.Textbox(label="๐Ÿ•’ Captured At (IST)")
        snapshot = gr.Image(label="๐Ÿ“ธ Snapshot Image")

    submit = gr.Button("๐Ÿ” Detect Weight")
    submit.click(process_image, inputs=image_input, outputs=[output_weight, timestamp, snapshot])

demo.launch()