Spaces:
Build error
Build error
File size: 1,322 Bytes
812afe6 a51774c 7c5b4e0 a51774c 3c2d17a a51774c 812afe6 a51774c 3c2d17a a51774c 7c5b4e0 a51774c 812afe6 7c5b4e0 812afe6 a51774c 3c2d17a 812afe6 7c5b4e0 |
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 |
import gradio as gr
from ocr_engine import extract_weight_from_image
from utils import get_ist_time
def process_image(image):
try:
print("📸 Image received:", type(image)) # Debug log
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, "-"
log_url = f"https://your-salesforce-site.com/log-weight?weight={weight}&time={timestamp}"
return f"{weight} g (Confidence: {confidence}%)", timestamp, image, log_url
except Exception as e:
print("❌ Error in process_image:", str(e)) # Debug log
return f"Error: {str(e)}", "-", None, "-"
iface = gr.Interface(
fn=process_image,
inputs=gr.Image(type="pil", label="Upload or Capture Snapshot", tool="editor"),
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 snapshot to detect weight automatically.",
live=True,
)
if __name__ == "__main__":
iface.launch() |