Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,37 @@
|
|
1 |
import gradio as gr
|
2 |
-
from PIL import Image, UnidentifiedImageError
|
3 |
-
from datetime import datetime
|
4 |
-
import pytz
|
5 |
from ocr_engine import extract_weight_from_image
|
|
|
6 |
|
7 |
-
def
|
8 |
try:
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
# OCR extraction
|
13 |
weight, confidence = extract_weight_from_image(image)
|
|
|
14 |
|
15 |
-
if
|
16 |
-
|
17 |
-
else:
|
18 |
-
result = "❌ No weight detected. Please upload a clearer image."
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
return None, "❌ Invalid image format."
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
outputs=[
|
28 |
-
gr.
|
29 |
-
gr.
|
|
|
|
|
30 |
],
|
31 |
title="⚖️ Auto Weight Logger",
|
32 |
-
description="Upload or capture a digital scale
|
33 |
-
|
34 |
)
|
35 |
|
36 |
if __name__ == "__main__":
|
37 |
-
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
from ocr_engine import extract_weight_from_image
|
3 |
+
from utils import get_ist_time
|
4 |
|
5 |
+
def process_image(image):
|
6 |
try:
|
7 |
+
if image is None:
|
8 |
+
return "No image provided", "-", None, "-"
|
9 |
|
|
|
10 |
weight, confidence = extract_weight_from_image(image)
|
11 |
+
timestamp = get_ist_time()
|
12 |
|
13 |
+
if not weight:
|
14 |
+
return "No weight detected", timestamp, image, "-"
|
|
|
|
|
15 |
|
16 |
+
log_url = f"https://your-salesforce-site.com/log-weight?weight={weight}&time={timestamp}"
|
17 |
+
return f"{weight} g (Confidence: {confidence}%)", timestamp, image, log_url
|
|
|
18 |
|
19 |
+
except Exception as e:
|
20 |
+
return f"Error: {str(e)}", "-", None, "-"
|
21 |
+
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=process_image,
|
24 |
+
inputs=gr.Image(type="pil", label="Upload or Capture Snapshot"),
|
25 |
outputs=[
|
26 |
+
gr.Textbox(label="Detected Weight"),
|
27 |
+
gr.Textbox(label="Captured At (IST)"),
|
28 |
+
gr.Image(label="Snapshot Image"),
|
29 |
+
gr.Textbox(label="Salesforce Log URL"),
|
30 |
],
|
31 |
title="⚖️ Auto Weight Logger",
|
32 |
+
description="Upload or capture a digital scale snapshot to detect weight automatically.",
|
33 |
+
live=True,
|
34 |
)
|
35 |
|
36 |
if __name__ == "__main__":
|
37 |
+
iface.launch()
|