Sanjayraju30 commited on
Commit
2883a04
·
verified ·
1 Parent(s): 5665756

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
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
- # Extract weight and confidence
14
  weight, confidence = extract_weight_from_image(img)
15
 
16
- # Format output in kg
17
- return f"{weight} kg (Confidence: {confidence}%)", ist_time, img
 
 
 
 
 
18
 
 
19
  with gr.Blocks(title="⚖️ Auto Weight Logger") as demo:
20
- gr.Markdown("## ⚖️ Auto Weight Logger")
21
- gr.Markdown("📷 **Upload or capture an image of a digital weight scale.** The app will auto-detect the weight in kilograms using OCR.")
22
 
23
  with gr.Row():
24
- image_input = gr.Image(type="pil", label="Upload / Capture Image")
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():