Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,8 @@ import pytz
|
|
5 |
from ocr_engine import extract_weight
|
6 |
from simple_salesforce import Salesforce
|
7 |
import base64
|
8 |
-
import os
|
9 |
|
10 |
-
# Salesforce credentials
|
11 |
SF_USERNAME = "[email protected]"
|
12 |
SF_PASSWORD = "autoweight@32"
|
13 |
SF_TOKEN = "UgiHKWT0aoZRX9gvTYDjAiRY"
|
@@ -22,21 +21,21 @@ def process_image(image):
|
|
22 |
weight = extract_weight(image)
|
23 |
ist = pytz.timezone('Asia/Kolkata')
|
24 |
timestamp = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S IST")
|
|
|
25 |
if not weight or "No valid" in weight:
|
26 |
return "❌ Unable to detect. Try again with a clearer image.", "", image, gr.update(visible=True)
|
27 |
|
28 |
-
# Save
|
29 |
-
|
30 |
-
buffered_image.save("snapshot.jpg")
|
31 |
with open("snapshot.jpg", "rb") as img_file:
|
32 |
snapshot_base64 = base64.b64encode(img_file.read()).decode('utf-8')
|
33 |
|
34 |
-
#
|
35 |
sf.Weight_Log__c.create({
|
36 |
"Captured_Weight__c": float(weight.replace("kg", "").strip()),
|
37 |
"Captured_At__c": datetime.now(ist).isoformat(),
|
38 |
"Snapshot_Image__c": snapshot_base64,
|
39 |
-
"Device_ID__c": "DEVICE-001",
|
40 |
"Status__c": "Captured"
|
41 |
})
|
42 |
|
|
|
5 |
from ocr_engine import extract_weight
|
6 |
from simple_salesforce import Salesforce
|
7 |
import base64
|
|
|
8 |
|
9 |
+
# Salesforce credentials
|
10 |
SF_USERNAME = "[email protected]"
|
11 |
SF_PASSWORD = "autoweight@32"
|
12 |
SF_TOKEN = "UgiHKWT0aoZRX9gvTYDjAiRY"
|
|
|
21 |
weight = extract_weight(image)
|
22 |
ist = pytz.timezone('Asia/Kolkata')
|
23 |
timestamp = datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S IST")
|
24 |
+
|
25 |
if not weight or "No valid" in weight:
|
26 |
return "❌ Unable to detect. Try again with a clearer image.", "", image, gr.update(visible=True)
|
27 |
|
28 |
+
# Save image as base64 (for Snapshot_Image__c)
|
29 |
+
image.save("snapshot.jpg")
|
|
|
30 |
with open("snapshot.jpg", "rb") as img_file:
|
31 |
snapshot_base64 = base64.b64encode(img_file.read()).decode('utf-8')
|
32 |
|
33 |
+
# Insert record into Salesforce
|
34 |
sf.Weight_Log__c.create({
|
35 |
"Captured_Weight__c": float(weight.replace("kg", "").strip()),
|
36 |
"Captured_At__c": datetime.now(ist).isoformat(),
|
37 |
"Snapshot_Image__c": snapshot_base64,
|
38 |
+
"Device_ID__c": "DEVICE-001",
|
39 |
"Status__c": "Captured"
|
40 |
})
|
41 |
|