Rekham1110 commited on
Commit
9afe9d3
·
verified ·
1 Parent(s): e3d782b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -7,6 +7,7 @@ from datetime import datetime
7
  import hashlib
8
  import shutil
9
  import base64
 
10
 
11
  # Load environment variables
12
  load_dotenv()
@@ -33,6 +34,9 @@ except Exception as e:
33
  # Valid milestones
34
  VALID_MILESTONES = ["Foundation", "Walls Erected", "Planning", "Completed"]
35
 
 
 
 
36
  # Deterministic AI prediction with fixed confidence and percent
37
  def mock_ai_model(image):
38
  img = image.convert("RGB")
@@ -68,7 +72,7 @@ def process_image(image, project_name):
68
  image_size_mb = os.path.getsize(image) / (1024 * 1024)
69
  if image_size_mb > 20:
70
  return "Error: Image size exceeds 20MB.", "Failure", "", "", 0
71
- if not str(image).lower().endswith(('.jpg', '.jpeg', '.png')):
72
  return "Error: Only JPG/PNG images are supported.", "Failure", "", "", 0
73
 
74
  # Save image to public folder temporarily before uploading to Salesforce
@@ -103,14 +107,17 @@ def process_image(image, project_name):
103
  # AI-based milestone and completion prediction
104
  milestone, percent_complete, confidence_score = mock_ai_model(img)
105
 
 
 
 
106
  # Create the Salesforce record with the image URL and AI prediction
107
  record = {
108
  "Name__c": project_name,
109
  "Current_Milestone__c": milestone,
110
  "Completion_Percentage__c": percent_complete,
111
- "Last_Updated_On__c": datetime,
112
  "Upload_Status__c": "Success",
113
- "Comments__c": f"{milestone} with {confidence_score*100}% confidence",
114
  "Last_Updated_Image__c": file_url
115
  }
116
 
 
7
  import hashlib
8
  import shutil
9
  import base64
10
+ import pytz
11
 
12
  # Load environment variables
13
  load_dotenv()
 
34
  # Valid milestones
35
  VALID_MILESTONES = ["Foundation", "Walls Erected", "Planning", "Completed"]
36
 
37
+ # Adjust the timezone to your local timezone (replace 'Asia/Kolkata' with your timezone if needed)
38
+ local_timezone = pytz.timezone("Asia/Kolkata")
39
+
40
  # Deterministic AI prediction with fixed confidence and percent
41
  def mock_ai_model(image):
42
  img = image.convert("RGB")
 
72
  image_size_mb = os.path.getsize(image) / (1024 * 1024)
73
  if image_size_mb > 20:
74
  return "Error: Image size exceeds 20MB.", "Failure", "", "", 0
75
+ if not str(image).lower().endswith(('.jpg', '.jpeg', '.png')):
76
  return "Error: Only JPG/PNG images are supported.", "Failure", "", "", 0
77
 
78
  # Save image to public folder temporarily before uploading to Salesforce
 
107
  # AI-based milestone and completion prediction
108
  milestone, percent_complete, confidence_score = mock_ai_model(img)
109
 
110
+ # Adjust the current time to local timezone
111
+ local_time = datetime.now(local_timezone).strftime("%Y-%m-%d %H:%M:%S")
112
+
113
  # Create the Salesforce record with the image URL and AI prediction
114
  record = {
115
  "Name__c": project_name,
116
  "Current_Milestone__c": milestone,
117
  "Completion_Percentage__c": percent_complete,
118
+ "Last_Updated_On__c": local_time, # Use the adjusted local time
119
  "Upload_Status__c": "Success",
120
+ "Comments__c": f"{milestone} with {confidence_score*100}% confidence", # Removed "AI Prediction:"
121
  "Last_Updated_Image__c": file_url
122
  }
123