Sanjayraju30 commited on
Commit
c042a27
·
verified ·
1 Parent(s): c3e8195

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -26,11 +26,11 @@ def process_image(image):
26
  ist = pytz.timezone('Asia/Kolkata')
27
  timestamp = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S IST")
28
 
29
- # Check for valid weight
30
  if not weight or ("No valid" in weight and "OCR:" not in weight):
31
  return "❌ Unable to detect. Try again with a clearer image.", "", image, gr.update(visible=True)
32
 
33
- # Extract numeric part and unit
34
  numeric_match = re.search(r'\d{1,5}(?:\.\d{1,3})?', weight)
35
  if not numeric_match:
36
  return "❌ Could not extract number", "", image, gr.update(visible=True)
@@ -42,16 +42,16 @@ def process_image(image):
42
  image_path = "snapshot.jpg"
43
  image.save(image_path)
44
 
45
- # Create Salesforce record
46
  record = sf.Weight_Log__c.create({
47
  "Captured_Weight__c": numeric_value,
48
- "Captured_Unit__c": unit, # ✅ make sure this exists in Salesforce
49
  "Captured_At__c": datetime.now(ist).isoformat(),
50
  "Device_ID__c": "DEVICE-001",
51
  "Status__c": "Confirmed"
52
  })
53
 
54
- # Upload image to Salesforce
55
  with open(image_path, "rb") as f:
56
  encoded_image = base64.b64encode(f.read()).decode("utf-8")
57
 
 
26
  ist = pytz.timezone('Asia/Kolkata')
27
  timestamp = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S IST")
28
 
29
+ # Handle missing or invalid output
30
  if not weight or ("No valid" in weight and "OCR:" not in weight):
31
  return "❌ Unable to detect. Try again with a clearer image.", "", image, gr.update(visible=True)
32
 
33
+ # Extract number and unit
34
  numeric_match = re.search(r'\d{1,5}(?:\.\d{1,3})?', weight)
35
  if not numeric_match:
36
  return "❌ Could not extract number", "", image, gr.update(visible=True)
 
42
  image_path = "snapshot.jpg"
43
  image.save(image_path)
44
 
45
+ # Create Weight_Log__c record
46
  record = sf.Weight_Log__c.create({
47
  "Captured_Weight__c": numeric_value,
48
+ "Captured_Unit__c": unit, # ✅ Must exist in Salesforce
49
  "Captured_At__c": datetime.now(ist).isoformat(),
50
  "Device_ID__c": "DEVICE-001",
51
  "Status__c": "Confirmed"
52
  })
53
 
54
+ # Upload image
55
  with open(image_path, "rb") as f:
56
  encoded_image = base64.b64encode(f.read()).decode("utf-8")
57