chandra7799 commited on
Commit
6b75cdd
·
verified ·
1 Parent(s): dc99826

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -44,7 +44,6 @@ def detect_milestone_from_image(image_path):
44
  """
45
  Placeholder for content-based milestone detection.
46
  In a real implementation, use a trained ML model to analyze image features.
47
- Here, we use a simplified approach based on image properties.
48
  """
49
  try:
50
  img = Image.open(image_path).convert("RGB")
@@ -112,21 +111,21 @@ def process_image(images, project_name, confirmed_milestone=None):
112
  img = Image.open(image)
113
  image_size_mb = os.path.getsize(image) / (1024 * 1024)
114
  if image_size_mb > 20:
115
- return "Error: Image {image} exceeds 20MB.", "Failure", "", "", 0, []
116
- if not str(image).lower().lower().endswith(('.jpg', '.jpeg', '.png')):
117
  return "Error: Only JPG or PNG images are supported.", "Failure", "", "", 0, []
118
 
119
  # Save image to local directory
120
  upload_dir = "public_uploads"
121
  os.makedirs(upload_dir, exist_ok=True)
122
- unique_id = datetime.now().strftime("%Y%m%d%H%M%S")")
123
- image_filename = f"{unique_id}_{{os.path.basename(image)}}"
124
  saved_path = os.path.join(upload_dir, image_filename)
125
- shutil.copy2(image, saved_path))
126
 
127
  # Upload image to Salesforce
128
  with open(saved_path, 'rb') as image_file:
129
- image_data = base64.b64encode(image_file.read()).decode('utf-8')
130
 
131
  try:
132
  content_version = {
@@ -140,14 +139,14 @@ def process_image(images, project_name, confirmed_milestone=None):
140
  file_urls.append(file_url)
141
  except Exception as e:
142
  logger.error(f"Failed to upload image to Salesforce: {str(e)}")
143
- return f"Error: Failed to upload image - {str(e)}", "Failure", "", "", 0, []
144
 
145
  milestone = detect_milestone_from_image(saved_path)
146
  milestones.append(milestone)
147
 
148
  # Determine final milestone
149
  final_milestone = confirmed_milestone or max(set(milestones), key=milestones.count)
150
- if not final_milestone in VALID_MILESTONES:
151
  return "Error: Invalid milestone detected.", "Failure", "", "", 0, []
152
 
153
  # Calculate completion percentage
 
44
  """
45
  Placeholder for content-based milestone detection.
46
  In a real implementation, use a trained ML model to analyze image features.
 
47
  """
48
  try:
49
  img = Image.open(image_path).convert("RGB")
 
111
  img = Image.open(image)
112
  image_size_mb = os.path.getsize(image) / (1024 * 1024)
113
  if image_size_mb > 20:
114
+ return f"Error: Image {image} exceeds 20MB.", "Failure", "", "", 0, []
115
+ if not str(image).lower().endswith(('.jpg', '.jpeg', '.png')):
116
  return "Error: Only JPG or PNG images are supported.", "Failure", "", "", 0, []
117
 
118
  # Save image to local directory
119
  upload_dir = "public_uploads"
120
  os.makedirs(upload_dir, exist_ok=True)
121
+ unique_id = datetime.now().strftime("%Y%m%d%H%M%S")
122
+ image_filename = f"{unique_id}_{os.path.basename(image)}"
123
  saved_path = os.path.join(upload_dir, image_filename)
124
+ shutil.copy2(image, saved_path)
125
 
126
  # Upload image to Salesforce
127
  with open(saved_path, 'rb') as image_file:
128
+ image_data = base64.b64encode(image_file.read()).decode('8')
129
 
130
  try:
131
  content_version = {
 
139
  file_urls.append(file_url)
140
  except Exception as e:
141
  logger.error(f"Failed to upload image to Salesforce: {str(e)}")
142
+ return f"Error: Failed to upload image - {str(e)}", "Failure", "", "", 0
143
 
144
  milestone = detect_milestone_from_image(saved_path)
145
  milestones.append(milestone)
146
 
147
  # Determine final milestone
148
  final_milestone = confirmed_milestone or max(set(milestones), key=milestones.count)
149
+ if final_milestone not in VALID_MILESTONES:
150
  return "Error: Invalid milestone detected.", "Failure", "", "", 0, []
151
 
152
  # Calculate completion percentage