Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,6 @@ load_dotenv()
|
|
| 12 |
SF_USERNAME = os.getenv("SF_USERNAME")
|
| 13 |
SF_PASSWORD = os.getenv("SF_PASSWORD")
|
| 14 |
SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN")
|
| 15 |
-
PUBLIC_URL_BASE = os.getenv("PUBLIC_URL_BASE", "https://your-public-host.com/public_uploads")
|
| 16 |
|
| 17 |
# Validate Salesforce credentials
|
| 18 |
if not all([SF_USERNAME, SF_PASSWORD, SF_SECURITY_TOKEN]):
|
|
@@ -56,7 +55,7 @@ def process_image(image, project_name):
|
|
| 56 |
if not str(image).lower().endswith(('.jpg', '.jpeg', '.png')):
|
| 57 |
return "Error: Only JPG/PNG images are supported.", "Failure", "", "", 0
|
| 58 |
|
| 59 |
-
# Save image to public folder
|
| 60 |
upload_dir = "public_uploads"
|
| 61 |
os.makedirs(upload_dir, exist_ok=True)
|
| 62 |
unique_id = datetime.now().strftime("%Y%m%d%H%M%S")
|
|
@@ -64,23 +63,21 @@ def process_image(image, project_name):
|
|
| 64 |
saved_image_path = os.path.join(upload_dir, image_filename)
|
| 65 |
shutil.copy(image, saved_image_path)
|
| 66 |
|
| 67 |
-
#
|
| 68 |
-
|
|
|
|
| 69 |
|
| 70 |
-
#
|
| 71 |
milestone, percent_complete, confidence_score = mock_ai_model(img)
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
formatted_timestamp = datetime.now().strftime("%d/%m/%Y, %I:%M %p")
|
| 75 |
-
|
| 76 |
-
# Salesforce record
|
| 77 |
record = {
|
| 78 |
"Name__c": project_name,
|
| 79 |
"Current_Milestone__c": milestone,
|
| 80 |
"Completion_Percentage__c": percent_complete,
|
| 81 |
-
"Last_Updated_On__c":
|
| 82 |
"Upload_Status__c": "Success",
|
| 83 |
-
"Comments__c": f"AI Prediction: {milestone} with {confidence_score
|
| 84 |
"Last_Updated_Image__c": image_url
|
| 85 |
}
|
| 86 |
|
|
|
|
| 12 |
SF_USERNAME = os.getenv("SF_USERNAME")
|
| 13 |
SF_PASSWORD = os.getenv("SF_PASSWORD")
|
| 14 |
SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN")
|
|
|
|
| 15 |
|
| 16 |
# Validate Salesforce credentials
|
| 17 |
if not all([SF_USERNAME, SF_PASSWORD, SF_SECURITY_TOKEN]):
|
|
|
|
| 55 |
if not str(image).lower().endswith(('.jpg', '.jpeg', '.png')):
|
| 56 |
return "Error: Only JPG/PNG images are supported.", "Failure", "", "", 0
|
| 57 |
|
| 58 |
+
# Save image to public folder for URL generation
|
| 59 |
upload_dir = "public_uploads"
|
| 60 |
os.makedirs(upload_dir, exist_ok=True)
|
| 61 |
unique_id = datetime.now().strftime("%Y%m%d%H%M%S")
|
|
|
|
| 63 |
saved_image_path = os.path.join(upload_dir, image_filename)
|
| 64 |
shutil.copy(image, saved_image_path)
|
| 65 |
|
| 66 |
+
# Create public URL assuming you're serving /public_uploads/ via static web server (e.g., on localhost or external host)
|
| 67 |
+
public_url_base = os.getenv("PUBLIC_URL_BASE", "http://localhost:7860/public_uploads")
|
| 68 |
+
image_url = f"{public_url_base}/{image_filename}"
|
| 69 |
|
| 70 |
+
# Predict
|
| 71 |
milestone, percent_complete, confidence_score = mock_ai_model(img)
|
| 72 |
|
| 73 |
+
# Construct Salesforce record
|
|
|
|
|
|
|
|
|
|
| 74 |
record = {
|
| 75 |
"Name__c": project_name,
|
| 76 |
"Current_Milestone__c": milestone,
|
| 77 |
"Completion_Percentage__c": percent_complete,
|
| 78 |
+
"Last_Updated_On__c": datetime.now().isoformat(),
|
| 79 |
"Upload_Status__c": "Success",
|
| 80 |
+
"Comments__c": f"AI Prediction: {milestone} with {confidence_score*100}% confidence",
|
| 81 |
"Last_Updated_Image__c": image_url
|
| 82 |
}
|
| 83 |
|