File size: 1,022 Bytes
a481416
 
 
 
 
 
 
 
 
 
 
 
 
 
8c50e18
 
a481416
 
8c50e18
 
 
 
6c9a667
a481416
8c50e18
 
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
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

    ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%d-%m-%Y %I:%M:%S %p")
    weight, confidence = extract_weight_from_image(img)
    return f"{weight} g (Confidence: {confidence}%)", ist_time, img

with gr.Blocks(title="βš–οΈ Auto Weight Logger") as demo:
    with gr.Column():
        gr.Markdown("## βš–οΈ Auto Weight Logger")
        image_input = gr.Image(type="pil", label="πŸ“· Upload or Capture Image")

        with gr.Row():
            output_weight = gr.Textbox(label="βš–οΈ Detected Weight")
            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()