Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,19 +9,25 @@ def process_image(img):
|
|
9 |
|
10 |
# Get IST time
|
11 |
ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%d-%m-%Y %I:%M:%S %p")
|
12 |
-
|
13 |
-
#
|
14 |
weight, confidence = extract_weight_from_image(img)
|
15 |
|
16 |
-
# Format output
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
|
|
|
19 |
with gr.Blocks(title="⚖️ Auto Weight Logger") as demo:
|
20 |
-
gr.Markdown("
|
21 |
-
gr.Markdown("
|
22 |
|
23 |
with gr.Row():
|
24 |
-
image_input = gr.Image(type="pil", label="Upload
|
25 |
output_weight = gr.Textbox(label="⚖️ Detected Weight (in kg)")
|
26 |
|
27 |
with gr.Row():
|
|
|
9 |
|
10 |
# Get IST time
|
11 |
ist_time = datetime.now(pytz.timezone("Asia/Kolkata")).strftime("%d-%m-%Y %I:%M:%S %p")
|
12 |
+
|
13 |
+
# Run OCR
|
14 |
weight, confidence = extract_weight_from_image(img)
|
15 |
|
16 |
+
# Format output with "kg"
|
17 |
+
if weight.replace('.', '', 1).isdigit():
|
18 |
+
formatted_weight = f"{weight} kg (Confidence: {confidence}%)"
|
19 |
+
else:
|
20 |
+
formatted_weight = f"{weight} (Confidence: {confidence}%)"
|
21 |
+
|
22 |
+
return formatted_weight, ist_time, img
|
23 |
|
24 |
+
# Gradio UI
|
25 |
with gr.Blocks(title="⚖️ Auto Weight Logger") as demo:
|
26 |
+
gr.Markdown("# ⚖️ Auto Weight Logger")
|
27 |
+
gr.Markdown("Upload or capture an image of a **digital scale display**. It will auto-detect the weight in kg.")
|
28 |
|
29 |
with gr.Row():
|
30 |
+
image_input = gr.Image(type="pil", label="📷 Upload or Capture Image")
|
31 |
output_weight = gr.Textbox(label="⚖️ Detected Weight (in kg)")
|
32 |
|
33 |
with gr.Row():
|