Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,25 +9,32 @@ def process_image(image):
|
|
9 |
return "No image provided", "", None
|
10 |
try:
|
11 |
weight = extract_weight(image)
|
12 |
-
|
13 |
ist = pytz.timezone('Asia/Kolkata')
|
14 |
-
|
15 |
-
|
16 |
-
return weight, now_ist, image
|
17 |
except Exception as e:
|
18 |
return f"Error: {str(e)}", "", None
|
19 |
|
20 |
-
with gr.Blocks() as demo:
|
21 |
-
gr.Markdown("
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
|
28 |
-
time_out = gr.Textbox(label="Captured At (IST)")
|
29 |
-
snapshot = gr.Image(label="Snapshot")
|
30 |
|
31 |
detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])
|
32 |
|
33 |
-
|
|
|
|
|
|
9 |
return "No image provided", "", None
|
10 |
try:
|
11 |
weight = extract_weight(image)
|
|
|
12 |
ist = pytz.timezone('Asia/Kolkata')
|
13 |
+
timestamp = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S IST")
|
14 |
+
return weight, timestamp, image
|
|
|
15 |
except Exception as e:
|
16 |
return f"Error: {str(e)}", "", None
|
17 |
|
18 |
+
with gr.Blocks(css=".gr-button {background-color: #2e7d32 !important; color: white !important;}") as demo:
|
19 |
+
gr.Markdown("""
|
20 |
+
<h1 style='text-align: center; color: #2e7d32;'>π· Auto Weight Logger</h1>
|
21 |
+
<p style='text-align: center;'>AI-powered OCR tool to detect weights (kg or grams) from digital balance display images.</p>
|
22 |
+
<hr style='border: 1px solid #ddd;'/>
|
23 |
+
""")
|
24 |
+
|
25 |
+
with gr.Row():
|
26 |
+
image_input = gr.Image(type="pil", label="π Upload or Capture Image", elem_id="img_upload")
|
27 |
+
|
28 |
+
detect_btn = gr.Button("π Detect Weight", elem_id="detect_btn")
|
29 |
|
30 |
+
with gr.Row():
|
31 |
+
weight_out = gr.Textbox(label="π¦ Detected Weight", placeholder="e.g., 72.4 kg", show_copy_button=True)
|
32 |
+
time_out = gr.Textbox(label="π Captured At (IST)", placeholder="e.g., 2025-06-30 14:32:10")
|
33 |
|
34 |
+
snapshot = gr.Image(label="πΈ Snapshot Preview")
|
|
|
|
|
35 |
|
36 |
detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot])
|
37 |
|
38 |
+
gr.Markdown("""
|
39 |
+
<br><p style='text-align: center; color: gray;'>Developed by Shalu | Powered by Hugging Face OCR π</p>
|
40 |
+
""")
|