Sanjayraju30 commited on
Commit
a51774c
·
verified ·
1 Parent(s): d9c67c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -1,22 +1,24 @@
1
  import gradio as gr
2
  from PIL import Image
3
- from datetime import datetime
4
  from ocr_engine import extract_weight_from_image
5
  from utils import get_ist_time
6
 
7
  def process_image(image):
8
- if image is None:
9
- return "No image provided", None, None, None
 
10
 
11
- weight, confidence = extract_weight_from_image(image)
12
- timestamp = get_ist_time()
13
- if not weight:
14
- return "No weight detected", timestamp, image, "-"
15
-
16
- return f"{weight} g (Confidence: {confidence}%)", timestamp, image, f"https://your-salesforce-site.com/log-weight?weight={weight}&time={timestamp}"
17
 
18
- title = "⚖️ Auto Weight Logger"
19
- description = "Upload or capture an image to extract the weight and log the result."
 
 
 
 
 
 
20
 
21
  iface = gr.Interface(
22
  fn=process_image,
@@ -27,8 +29,8 @@ iface = gr.Interface(
27
  gr.Image(label="Snapshot Image"),
28
  gr.Textbox(label="Salesforce Log URL"),
29
  ],
30
- title=title,
31
- description=description,
32
  live=True,
33
  )
34
 
 
1
  import gradio as gr
2
  from PIL import Image
 
3
  from ocr_engine import extract_weight_from_image
4
  from utils import get_ist_time
5
 
6
  def process_image(image):
7
+ try:
8
+ if image is None:
9
+ return "No image provided", "-", None, "-"
10
 
11
+ weight, confidence = extract_weight_from_image(image)
12
+ timestamp = get_ist_time()
 
 
 
 
13
 
14
+ if not weight:
15
+ return "No weight detected", timestamp, image, "-"
16
+
17
+ log_url = f"https://your-salesforce-site.com/log-weight?weight={weight}&time={timestamp}"
18
+ return f"{weight} g (Confidence: {confidence}%)", timestamp, image, log_url
19
+
20
+ except Exception as e:
21
+ return f"Error: {str(e)}", "-", None, "-"
22
 
23
  iface = gr.Interface(
24
  fn=process_image,
 
29
  gr.Image(label="Snapshot Image"),
30
  gr.Textbox(label="Salesforce Log URL"),
31
  ],
32
+ title="⚖️ Auto Weight Logger",
33
+ description="Upload or capture an image to extract the weight and log the result.",
34
  live=True,
35
  )
36