Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
from datetime import datetime
|
4 |
+
from ocr_engine import extract_weight_from_image
|
5 |
+
from utils import get_ist_time
|
6 |
+
|
7 |
+
def process_image(image):
|
8 |
+
if image is None:
|
9 |
+
return "No image provided", None, None, None
|
10 |
+
|
11 |
+
weight, confidence = extract_weight_from_image(image)
|
12 |
+
timestamp = get_ist_time()
|
13 |
+
if not weight:
|
14 |
+
return "No weight detected", timestamp, image, "-"
|
15 |
+
|
16 |
+
return f"{weight} g (Confidence: {confidence}%)", timestamp, image, f"https://your-salesforce-site.com/log-weight?weight={weight}&time={timestamp}"
|
17 |
+
|
18 |
+
title = "⚖️ Auto Weight Logger"
|
19 |
+
description = "Upload or capture an image to extract the weight and log the result."
|
20 |
+
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=process_image,
|
23 |
+
inputs=gr.Image(type="pil", source="upload", tool="editor", label="Upload or Capture Snapshot"),
|
24 |
+
outputs=[
|
25 |
+
gr.Textbox(label="Detected Weight"),
|
26 |
+
gr.Textbox(label="Captured At (IST)"),
|
27 |
+
gr.Image(label="Snapshot Image"),
|
28 |
+
gr.Textbox(label="Salesforce Log URL"),
|
29 |
+
],
|
30 |
+
title=title,
|
31 |
+
description=description,
|
32 |
+
live=True,
|
33 |
+
)
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
iface.launch()
|