Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,26 +4,26 @@ from datetime import datetime
|
|
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 |
-
|
12 |
-
return f"{weight} grams",
|
13 |
except Exception as e:
|
14 |
-
return f"Error: {str(e)}", "
|
15 |
|
16 |
with gr.Blocks() as demo:
|
17 |
-
gr.Markdown("## π· Auto Weight Logger β
|
18 |
-
gr.Markdown("Upload a
|
19 |
|
20 |
-
image_input = gr.Image(type="pil", label="π Upload or Capture
|
21 |
|
22 |
detect_btn = gr.Button("π Detect Weight")
|
23 |
-
|
24 |
-
|
25 |
-
|
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 |
|
|
|
4 |
from ocr_engine import extract_weight
|
5 |
|
6 |
def process_image(image):
|
7 |
+
if image is None:
|
8 |
+
return "No image provided", "", None
|
9 |
+
|
10 |
try:
|
|
|
|
|
11 |
weight = extract_weight(image)
|
12 |
+
timestamp = datetime.now().astimezone().strftime("%Y-%m-%d %H:%M:%S %Z")
|
13 |
+
return f"{weight} grams", timestamp, image
|
14 |
except Exception as e:
|
15 |
+
return f"Error: {str(e)}", "", None
|
16 |
|
17 |
with gr.Blocks() as demo:
|
18 |
+
gr.Markdown("## π· Auto Weight Logger β Hugging Face OCR Edition")
|
19 |
+
gr.Markdown("Upload a digital scale image. Detects weight using a transformer-based OCR model.")
|
20 |
|
21 |
+
image_input = gr.Image(type="pil", label="π Upload or Capture Image")
|
22 |
|
23 |
detect_btn = gr.Button("π Detect Weight")
|
24 |
+
weight_out = gr.Textbox(label="Detected Weight")
|
25 |
+
time_out = gr.Textbox(label="Captured At (IST)")
|
26 |
+
snapshot = gr.Image(label="Snapshot")
|
|
|
27 |
|
28 |
detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])
|
29 |
|