Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,25 +4,26 @@ from datetime import datetime
|
|
4 |
from ocr_engine import extract_weight
|
5 |
|
6 |
def process_image(image):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
12 |
|
13 |
with gr.Blocks() as demo:
|
14 |
gr.Markdown("## π· Auto Weight Logger β OCR-Based Smart Scale Reader")
|
15 |
-
gr.Markdown("Upload
|
16 |
|
17 |
-
image_input = gr.Image(type="pil", label="π Upload or Capture Image")
|
18 |
|
19 |
detect_btn = gr.Button("π Detect Weight")
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
snapshot = gr.Image(label="Snapshot")
|
26 |
|
27 |
detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])
|
28 |
|
|
|
4 |
from ocr_engine import extract_weight
|
5 |
|
6 |
def process_image(image):
|
7 |
+
try:
|
8 |
+
if image is None:
|
9 |
+
return "No image provided", "No timestamp", None
|
10 |
+
weight = extract_weight(image)
|
11 |
+
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
12 |
+
return f"{weight} grams", now, image
|
13 |
+
except Exception as e:
|
14 |
+
return f"Error: {str(e)}", "Error", None
|
15 |
|
16 |
with gr.Blocks() as demo:
|
17 |
gr.Markdown("## π· Auto Weight Logger β OCR-Based Smart Scale Reader")
|
18 |
+
gr.Markdown("Upload a photo of a digital scale. The app will detect and log the weight.")
|
19 |
|
20 |
+
image_input = gr.Image(type="pil", label="π Upload or Capture Digital Scale Image")
|
21 |
|
22 |
detect_btn = gr.Button("π Detect Weight")
|
23 |
|
24 |
+
weight_out = gr.Textbox(label="π¦ Detected Weight")
|
25 |
+
time_out = gr.Textbox(label="β±οΈ Captured At (IST)")
|
26 |
+
snapshot = gr.Image(label="πΌοΈ Snapshot Preview")
|
|
|
|
|
27 |
|
28 |
detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])
|
29 |
|