Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,41 @@
|
|
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(
|
6 |
-
|
7 |
-
|
8 |
-
return "No image provided", "-", None, "-"
|
9 |
-
|
10 |
-
weight, confidence = extract_weight_from_image(image)
|
11 |
-
timestamp = get_ist_time()
|
12 |
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
|
|
|
|
|
|
23 |
fn=process_image,
|
24 |
-
inputs=gr.Image(type="pil", label="Upload or Capture
|
25 |
outputs=[
|
26 |
-
gr.
|
27 |
-
gr.
|
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
|
33 |
-
|
34 |
)
|
35 |
|
36 |
if __name__ == "__main__":
|
37 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
from datetime import datetime
|
4 |
+
import pytz
|
5 |
from ocr_engine import extract_weight_from_image
|
|
|
6 |
|
7 |
+
def process_image(img):
|
8 |
+
# Convert image to RGB in case it's RGBA or grayscale
|
9 |
+
img = img.convert("RGB")
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Get IST timestamp
|
12 |
+
ist = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
|
13 |
|
14 |
+
# Run OCR
|
15 |
+
weight, confidence = extract_weight_from_image(img)
|
16 |
|
17 |
+
# Format output
|
18 |
+
result = f"📅 Captured At (IST): {ist}\n"
|
19 |
+
if confidence > 0:
|
20 |
+
result += f"⚖️ Detected Weight: **{weight}**\n"
|
21 |
+
result += f"✅ Confidence: `{confidence:.2f}`"
|
22 |
+
else:
|
23 |
+
result += "❌ No weight detected. Try a clearer image."
|
24 |
|
25 |
+
return img, result
|
26 |
+
|
27 |
+
# Gradio UI
|
28 |
+
demo = gr.Interface(
|
29 |
fn=process_image,
|
30 |
+
inputs=gr.Image(type="pil", label="Upload or Capture Image"),
|
31 |
outputs=[
|
32 |
+
gr.Image(type="pil", label="Snapshot"),
|
33 |
+
gr.Markdown(label="Weight Result")
|
|
|
|
|
34 |
],
|
35 |
+
title="⚖️ Auto Weight Logger (PaddleOCR)",
|
36 |
+
description="Upload or capture an image of a weighing scale. This app uses PaddleOCR to detect the weight value.",
|
37 |
+
allow_flagging="never"
|
38 |
)
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
+
demo.launch()
|