Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ 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:
|
@@ -13,7 +13,7 @@ def detect_weight(image: Image.Image):
|
|
13 |
weight, confidence = extract_weight_from_image(image)
|
14 |
|
15 |
if confidence > 0:
|
16 |
-
result = f"β
**Detected Weight:** {weight}\n
|
17 |
else:
|
18 |
result = "β No weight detected. Please upload a clearer image."
|
19 |
return image, result
|
@@ -21,9 +21,6 @@ def detect_weight(image: Image.Image):
|
|
21 |
return None, "β Invalid image format."
|
22 |
|
23 |
# Gradio UI
|
24 |
-
title = "βοΈ Auto Weight Logger"
|
25 |
-
description = "Upload or capture an image of a digital weighing scale to automatically extract the weight using OCR."
|
26 |
-
|
27 |
demo = gr.Interface(
|
28 |
fn=detect_weight,
|
29 |
inputs=gr.Image(type="pil", label="Upload or Capture Image"),
|
@@ -31,8 +28,8 @@ demo = gr.Interface(
|
|
31 |
gr.Image(type="pil", label="Snapshot"),
|
32 |
gr.Markdown(label="Result")
|
33 |
],
|
34 |
-
title=
|
35 |
-
description=
|
36 |
allow_flagging="never"
|
37 |
)
|
38 |
|
|
|
2 |
from PIL import Image, UnidentifiedImageError
|
3 |
from datetime import datetime
|
4 |
import pytz
|
5 |
+
from ocr_engine import extract_weight_from_image # Make sure this file exists
|
6 |
|
7 |
def detect_weight(image: Image.Image):
|
8 |
try:
|
|
|
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
|
|
|
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"),
|
|
|
28 |
gr.Image(type="pil", label="Snapshot"),
|
29 |
gr.Markdown(label="Result")
|
30 |
],
|
31 |
+
title="βοΈ Auto Weight Logger",
|
32 |
+
description="Upload or capture a digital scale snapshot to detect weight automatically.",
|
33 |
allow_flagging="never"
|
34 |
)
|
35 |
|