varshakolanu commited on
Commit
8b2877d
·
verified ·
1 Parent(s): c946ef1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -14,11 +14,15 @@ load_dotenv()
14
  generator = pipeline("text-generation", model="distilgpt2")
15
 
16
  # Initialize Salesforce connection using environment variables
17
- sf = Salesforce(
18
- username=os.getenv("SF_USERNAME"),
19
- password=os.getenv("SF_PASSWORD"),
20
- security_token=os.getenv("SF_SECURITY_TOKEN")
21
- )
 
 
 
 
22
 
23
  @app.route('/generate-ai-data', methods=['POST'])
24
  def generate_ai_data():
@@ -26,6 +30,12 @@ def generate_ai_data():
26
  Generate AI coaching data and reports based on supervisor and project data.
27
  This endpoint is called by Salesforce when a new project is created or during daily refresh.
28
  """
 
 
 
 
 
 
29
  try:
30
  data = request.get_json()
31
  supervisor_id = data['supervisor_id']
@@ -113,4 +123,4 @@ def generate_ai_data():
113
  }), 500
114
 
115
  if __name__ == "__main__":
116
- app.run(host="0.0.0.0", port=8080)
 
14
  generator = pipeline("text-generation", model="distilgpt2")
15
 
16
  # Initialize Salesforce connection using environment variables
17
+ try:
18
+ sf = Salesforce(
19
+ username=os.getenv("SF_USERNAME"),
20
+ password=os.getenv("SF_PASSWORD"),
21
+ security_token=os.getenv("SF_SECURITY_TOKEN")
22
+ )
23
+ except Exception as e:
24
+ print(f"Error connecting to Salesforce: {str(e)}")
25
+ sf = None
26
 
27
  @app.route('/generate-ai-data', methods=['POST'])
28
  def generate_ai_data():
 
30
  Generate AI coaching data and reports based on supervisor and project data.
31
  This endpoint is called by Salesforce when a new project is created or during daily refresh.
32
  """
33
+ if sf is None:
34
+ return jsonify({
35
+ "status": "error",
36
+ "message": "Salesforce connection failed. Check credentials in .env file."
37
+ }), 500
38
+
39
  try:
40
  data = request.get_json()
41
  supervisor_id = data['supervisor_id']
 
123
  }), 500
124
 
125
  if __name__ == "__main__":
126
+ app.run(host="0.0.0.0", port=7860)