Ajay98 commited on
Commit
869f73f
·
verified ·
1 Parent(s): be3c563

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -58
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
- if not os.path.exists(unknown_folder):
31
- print(f"Error: Unknown folder '{unknown_folder}' does not exist.")
32
- return
33
-
34
- for staff_image in os.listdir(staff_folder):
35
- staff_image_path = os.path.join(staff_folder, staff_image)
36
- found_match = False
37
-
38
- for unknown_image in os.listdir(unknown_folder):
39
- unknown_image_path = os.path.join(unknown_folder, unknown_image)
40
-
41
- if compare_images(staff_image_path, unknown_image_path):
42
- print(f"Match found: {staff_image} matches {unknown_image} (Staff)")
43
- found_match = True
44
- break
45
-
46
- if not found_match:
47
- print(f"No match found for {staff_image} (Unknown)")
48
-
49
- # Update to your actual path
50
-
51
- if __name__ == "__main__":
52
- # Print paths for debugging
53
- print(f"Staff folder path: {staff_folder_path}")
54
- print(f"Unknown folder path: {unknown_folder_path}")
55
-
56
- # Compare folders
57
-
58
-
59
- compare_folders(staff_folder_path, unknown_folder_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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})