Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,59 +1,51 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import cv2
|
| 3 |
-
import numpy as np
|
| 4 |
-
# Define the paths
|
| 5 |
-
staff_folder_path = r"C:\Test1" # Update to your actual path
|
| 6 |
-
unknown_folder_path = r"C:\Test2"
|
| 7 |
-
|
| 8 |
-
def compare_images(image1, image2):
|
| 9 |
-
img1 = cv2.imread(image1)
|
| 10 |
-
img2 = cv2.imread(image2)
|
| 11 |
-
|
| 12 |
-
if img1 is None or img2 is None:
|
| 13 |
-
return False
|
| 14 |
-
|
| 15 |
-
img1 = cv2.resize(img1, (100, 100))
|
| 16 |
-
img2 = cv2.resize(img2, (100, 100))
|
| 17 |
-
|
| 18 |
-
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
|
| 19 |
-
gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
|
| 20 |
-
|
| 21 |
-
score, _ = cv2.compare_ssim(gray1, gray2, full=True)
|
| 22 |
-
|
| 23 |
-
return score >= 0.9
|
| 24 |
-
|
| 25 |
-
def compare_folders(staff_folder, unknown_folder):
|
| 26 |
-
if not os.path.exists(staff_folder):
|
| 27 |
-
print(f"Error: Staff folder '{staff_folder}' does not exist.")
|
| 28 |
-
return
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
+
import os
|
| 3 |
+
import requests
|
| 4 |
+
import json
|
| 5 |
+
from salesforce import Salesforce
|
| 6 |
+
from jwt import encode
|
| 7 |
+
import base64
|
| 8 |
+
from cryptography.hazmat.primitives import serialization
|
| 9 |
+
from cryptography.hazmat.backends import default_backend
|
| 10 |
+
|
| 11 |
+
# Salesforce credentials
|
| 12 |
+
CONSUMER_KEY = os.environ['SALESFORCE_CONSUMER_KEY']
|
| 13 |
+
CONSUMER_SECRET = os.environ['SALESFORCE_CONSUMER_SECRET']
|
| 14 |
+
USERNAME = os.environ['SALESFORCE_USERNAME']
|
| 15 |
+
PASSWORD = os.environ['SALESFORCE_PASSWORD']
|
| 16 |
+
SECURITY_TOKEN = os.environ['SALESFORCE_SECURITY_TOKEN']
|
| 17 |
+
|
| 18 |
+
# Custom object and field
|
| 19 |
+
OBJECT_NAME = 'Guest__c'
|
| 20 |
+
FIELD_NAME = 'Adhar_Card_Photo__c'
|
| 21 |
+
|
| 22 |
+
# Authenticate and get access token
|
| 23 |
+
def get_access_token():
|
| 24 |
+
payload = {
|
| 25 |
+
'grant_type': 'password',
|
| 26 |
+
'client_id': CONSUMER_KEY,
|
| 27 |
+
'client_secret': CONSUMER_SECRET,
|
| 28 |
+
'username': USERNAME,
|
| 29 |
+
'password': PASSWORD + SECURITY_TOKEN
|
| 30 |
+
}
|
| 31 |
+
response = requests.post('(link unavailable)', data=payload)
|
| 32 |
+
return response.json()['access_token']
|
| 33 |
+
|
| 34 |
+
# Upload image to Salesforce
|
| 35 |
+
def upload_image(image_path, image_name):
|
| 36 |
+
access_token = get_access_token()
|
| 37 |
+
sf = Salesforce(instance_url='(link unavailable)',
|
| 38 |
+
session_id=access_token)
|
| 39 |
+
|
| 40 |
+
# Read image content
|
| 41 |
+
with open(image_path, 'rb') as image_file:
|
| 42 |
+
image_content = image_file.read()
|
| 43 |
+
image_base64 = base64.b64encode(image_content).decode('utf-8')
|
| 44 |
+
|
| 45 |
+
# Create or update record
|
| 46 |
+
record = sf.query(f"SELECT Id FROM {OBJECT_NAME} WHERE Name = '{image_name}'")
|
| 47 |
+
if record['records']:
|
| 48 |
+
record_id = record['records'][0]['Id']
|
| 49 |
+
sf.update(OBJECT_NAME, {'Id': record_id, FIELD_NAME: image_base64})
|
| 50 |
+
else:
|
| 51 |
+
sf.create(OBJECT_NAME, {FIELD_NAME: image_base64, 'Name': image_name})
|