Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,10 @@ import base64
|
|
| 7 |
from io import BytesIO
|
| 8 |
import json
|
| 9 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Salesforce Credentials
|
| 12 |
SALESFORCE_USERNAME = "drone@sathkrutha.com"
|
|
@@ -25,7 +29,9 @@ try:
|
|
| 25 |
security_token=SALESFORCE_SECURITY_TOKEN,
|
| 26 |
instance_url=SALESFORCE_INSTANCE_URL
|
| 27 |
)
|
|
|
|
| 28 |
except Exception as e:
|
|
|
|
| 29 |
raise Exception(f"Failed to connect to Salesforce: {str(e)}")
|
| 30 |
|
| 31 |
# Load Model
|
|
@@ -86,8 +92,10 @@ def upload_image_to_salesforce(image, filename="detected_image.jpg", record_id=N
|
|
| 86 |
"VersionData": img_data,
|
| 87 |
"FirstPublishLocationId": record_id if record_id else None
|
| 88 |
})
|
|
|
|
| 89 |
return content_version["id"]
|
| 90 |
except Exception as e:
|
|
|
|
| 91 |
raise Exception(f"Failed to upload image to Salesforce: {str(e)}")
|
| 92 |
|
| 93 |
# Detect defects and integrate with Salesforce
|
|
@@ -162,6 +170,7 @@ def detect_defects(image):
|
|
| 162 |
return result_image, output
|
| 163 |
|
| 164 |
except Exception as e:
|
|
|
|
| 165 |
return None, {"error": f"Processing failed: {str(e)}"}
|
| 166 |
|
| 167 |
# Gradio Interface
|
|
@@ -177,4 +186,4 @@ demo = gr.Interface(
|
|
| 177 |
)
|
| 178 |
|
| 179 |
if __name__ == "__main__":
|
| 180 |
-
demo.launch()
|
|
|
|
| 7 |
from io import BytesIO
|
| 8 |
import json
|
| 9 |
from datetime import datetime
|
| 10 |
+
import logging
|
| 11 |
+
|
| 12 |
+
# Setup logging
|
| 13 |
+
logging.basicConfig(level=logging.INFO)
|
| 14 |
|
| 15 |
# Salesforce Credentials
|
| 16 |
SALESFORCE_USERNAME = "drone@sathkrutha.com"
|
|
|
|
| 29 |
security_token=SALESFORCE_SECURITY_TOKEN,
|
| 30 |
instance_url=SALESFORCE_INSTANCE_URL
|
| 31 |
)
|
| 32 |
+
logging.info("Salesforce connection established.")
|
| 33 |
except Exception as e:
|
| 34 |
+
logging.error(f"Failed to connect to Salesforce: {str(e)}")
|
| 35 |
raise Exception(f"Failed to connect to Salesforce: {str(e)}")
|
| 36 |
|
| 37 |
# Load Model
|
|
|
|
| 92 |
"VersionData": img_data,
|
| 93 |
"FirstPublishLocationId": record_id if record_id else None
|
| 94 |
})
|
| 95 |
+
logging.info(f"Image uploaded to Salesforce with ContentVersion ID: {content_version['id']}")
|
| 96 |
return content_version["id"]
|
| 97 |
except Exception as e:
|
| 98 |
+
logging.error(f"Failed to upload image to Salesforce: {str(e)}")
|
| 99 |
raise Exception(f"Failed to upload image to Salesforce: {str(e)}")
|
| 100 |
|
| 101 |
# Detect defects and integrate with Salesforce
|
|
|
|
| 170 |
return result_image, output
|
| 171 |
|
| 172 |
except Exception as e:
|
| 173 |
+
logging.error(f"Processing failed: {str(e)}")
|
| 174 |
return None, {"error": f"Processing failed: {str(e)}"}
|
| 175 |
|
| 176 |
# Gradio Interface
|
|
|
|
| 186 |
)
|
| 187 |
|
| 188 |
if __name__ == "__main__":
|
| 189 |
+
demo.launch()
|