Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,19 +6,23 @@ from ocr_engine import extract_weight
|
|
6 |
|
7 |
def process_image(image):
|
8 |
if image is None:
|
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 |
-
|
|
|
|
|
|
|
|
|
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;'>
|
22 |
<hr style='border: 1px solid #ddd;'/>
|
23 |
""")
|
24 |
|
@@ -32,12 +36,14 @@ with gr.Blocks(css=".gr-button {background-color: #2e7d32 !important; color: whi
|
|
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 |
-
<
|
40 |
""")
|
41 |
|
42 |
-
# π¨ REQUIRED for Hugging Face to recognize the app
|
43 |
demo.launch()
|
|
|
6 |
|
7 |
def process_image(image):
|
8 |
if image is None:
|
9 |
+
return "No image provided", "", None, gr.update(visible=True)
|
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 |
+
|
15 |
+
if not weight:
|
16 |
+
return "β Unable to detect. Try again with clearer image.", "", image, gr.update(visible=True)
|
17 |
+
|
18 |
+
return weight, timestamp, image, gr.update(visible=False)
|
19 |
except Exception as e:
|
20 |
+
return f"Error: {str(e)}", "", None, gr.update(visible=True)
|
21 |
|
22 |
with gr.Blocks(css=".gr-button {background-color: #2e7d32 !important; color: white !important;}") as demo:
|
23 |
gr.Markdown("""
|
24 |
<h1 style='text-align: center; color: #2e7d32;'>π· Auto Weight Logger</h1>
|
25 |
+
<p style='text-align: center;'>Upload or capture a digital weight image. Detects weight with AI OCR.</p>
|
26 |
<hr style='border: 1px solid #ddd;'/>
|
27 |
""")
|
28 |
|
|
|
36 |
time_out = gr.Textbox(label="π Captured At (IST)", placeholder="e.g., 2025-06-30 14:32:10")
|
37 |
|
38 |
snapshot = gr.Image(label="πΈ Snapshot Preview")
|
39 |
+
retake_btn = gr.Button("π Retake / Try Again", visible=False)
|
40 |
|
41 |
+
detect_btn.click(fn=process_image, inputs=image_input, outputs=[weight_out, time_out, snapshot, retake_btn])
|
42 |
+
retake_btn.click(fn=lambda: ("", "", None, gr.update(visible=False)),
|
43 |
+
inputs=[], outputs=[weight_out, time_out, snapshot, retake_btn])
|
44 |
|
45 |
gr.Markdown("""
|
46 |
+
<p style='text-align: center; color: gray;'>Tip: Ensure image is glare-free and focused. <br>Developed by Shalu β’ Hugging Face OCR β‘</p>
|
47 |
""")
|
48 |
|
|
|
49 |
demo.launch()
|