Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -2,25 +2,25 @@ 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 detect_weight(image: Image.Image):
|
8 |
try:
|
9 |
-
# Get IST
|
10 |
ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
|
11 |
|
12 |
-
#
|
13 |
weight, confidence = extract_weight_from_image(image)
|
14 |
|
15 |
if confidence > 0:
|
16 |
result = f"β
**Detected Weight:** {weight} \nπ **Confidence:** {confidence:.2f} \nπ **Captured At (IST):** {ist_time}"
|
17 |
else:
|
18 |
result = "β No weight detected. Please upload a clearer image."
|
|
|
19 |
return image, result
|
20 |
except UnidentifiedImageError:
|
21 |
return None, "β Invalid image format."
|
22 |
|
23 |
-
# Gradio UI
|
24 |
demo = gr.Interface(
|
25 |
fn=detect_weight,
|
26 |
inputs=gr.Image(type="pil", label="Upload or Capture Image"),
|
@@ -29,7 +29,7 @@ demo = gr.Interface(
|
|
29 |
gr.Markdown(label="Result")
|
30 |
],
|
31 |
title="βοΈ Auto Weight Logger",
|
32 |
-
description="Upload or capture a digital scale
|
33 |
allow_flagging="never"
|
34 |
)
|
35 |
|
|
|
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 detect_weight(image: Image.Image):
|
8 |
try:
|
9 |
+
# Get IST time
|
10 |
ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S")
|
11 |
|
12 |
+
# OCR extraction
|
13 |
weight, confidence = extract_weight_from_image(image)
|
14 |
|
15 |
if confidence > 0:
|
16 |
result = f"β
**Detected Weight:** {weight} \nπ **Confidence:** {confidence:.2f} \nπ **Captured At (IST):** {ist_time}"
|
17 |
else:
|
18 |
result = "β No weight detected. Please upload a clearer image."
|
19 |
+
|
20 |
return image, result
|
21 |
except UnidentifiedImageError:
|
22 |
return None, "β Invalid image format."
|
23 |
|
|
|
24 |
demo = gr.Interface(
|
25 |
fn=detect_weight,
|
26 |
inputs=gr.Image(type="pil", label="Upload or Capture Image"),
|
|
|
29 |
gr.Markdown(label="Result")
|
30 |
],
|
31 |
title="βοΈ Auto Weight Logger",
|
32 |
+
description="Upload or capture a digital scale image to detect weight automatically.",
|
33 |
allow_flagging="never"
|
34 |
)
|
35 |
|