Autoweight / app.py
Sanjayraju30's picture
Update app.py
8daea2b verified
raw
history blame
1.17 kB
import gradio as gr
from ocr_engine import extract_weight_from_image
from utils import get_ist_time
def process_image(image):
try:
if image is None:
return "No image provided", "-", None, "-"
weight, confidence = extract_weight_from_image(image)
timestamp = get_ist_time()
if not weight:
return "No weight detected", timestamp, image, "-"
sf_url = f"https://your-salesforce-site.com/log-weight?weight={weight}&time={timestamp}"
return f"{weight} g (Confidence: {confidence}%)", timestamp, image, sf_url
except Exception as e:
return f"Error: {str(e)}", "-", None, "-"
iface = gr.Interface(
fn=process_image,
inputs=gr.Image(type="pil", label="Upload or Capture Snapshot"),
outputs=[
gr.Textbox(label="Detected Weight"),
gr.Textbox(label="Captured At (IST)"),
gr.Image(label="Snapshot Image"),
gr.Textbox(label="Salesforce Log URL"),
],
title="⚖️ Auto Weight Logger",
description="Upload or capture a digital scale image to extract the weight.",
live=True,
)
if __name__ == "__main__":
iface.launch()