Sanjayraju30's picture
Update app.py
06308c8 verified
raw
history blame
1.27 kB
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, "No OCR output"
ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%d-%m-%Y %I:%M:%S %p")
weight, confidence, raw_text = extract_weight_from_image(img)
return f"{weight} kg (Confidence: {confidence}%)", ist_time, img, raw_text
with gr.Blocks(title="βš–οΈ Auto Weight Logger") as demo:
gr.Markdown("## βš–οΈ Auto Weight Logger")
gr.Markdown("πŸ“· **Upload or capture an image of a digital weight scale.** The app will auto-detect the weight in kilograms using OCR.")
with gr.Row():
image_input = gr.Image(type="pil", label="Upload / 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")
with gr.Row():
debug_output = gr.Textbox(label="πŸͺ΅ Raw OCR Output")
submit = gr.Button("πŸ” Detect Weight")
submit.click(process_image, inputs=image_input, outputs=[output_weight, timestamp, snapshot, debug_output])
demo.launch()