varshakolanu commited on
Commit
67259ed
·
verified ·
1 Parent(s): 408c8b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -24
app.py CHANGED
@@ -6,38 +6,39 @@ from datetime import datetime
6
  from simple_salesforce import Salesforce, SalesforceAuthenticationFailed
7
  from flask import Flask, jsonify, request, render_template, redirect, url_for
8
 
9
- # Configure logging with more detail
10
- logging.basicConfig(
11
- level=logging.DEBUG, # Set to DEBUG for detailed logs
12
- format='%(asctime)s - %(levelname)s - %(message)s',
13
- handlers=[
14
- logging.StreamHandler() # Output logs to console
15
- ])
16
  logger = logging.getLogger(__name__)
17
 
18
- # Hugging Face API configuration
19
- HUGGING_FACE_API_URL = "https://api-inference.huggingface.co/models/distilgpt2"
20
- HUGGING_FACE_API_TOKEN = "your_hugging_face_api_token_here" # Replace with your actual Hugging Face API token
21
 
22
- # Salesforce credentials (use environment variables for security)
23
- #SF_USERNAME = os.getenv('Ai@Coach.com')
24
- #SF_PASSWORD = os.getenv('Teja90325@')
25
- #SF_SECURITY_TOKEN = os.getenv('clceSdBgQ30Rx9BSC66gAcRx')
26
- #SF_DOMAIN = os.getenv('SF_DOMAIN', 'login') # Default to 'login' if not set
27
- #HUGGINGFACE_API_KEY = os.getenv('HUGGINGFACE_API_KEY')
28
-
29
- # Salesforce configuration
30
- #SALESFORCE_USERNAME = "Ai@Coach.com"
31
- #SALESFORCE_PASSWORD = "Teja90325@"
32
- #SALESFORCE_SECURITY_TOKEN = "clceSdBgQ30Rx9BSC66gAcRx"
33
- #SALESFORCE_DOMAIN = "login.salesforce.com"
34
-
35
- #Salesforce credentials
36
  SF_USERNAME = os.getenv("SF_USERNAME", "Ai@Coach.com")
37
  SF_PASSWORD = os.getenv("SF_PASSWORD", "Teja90325@")
38
  SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN", "clceSdBgQ30Rx9BSC66gAcRx")
39
  SF_DOMAIN = os.getenv("SF_DOMAIN", "login")
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  # Validate configuration
43
  if not HUGGING_FACE_API_TOKEN:
 
6
  from simple_salesforce import Salesforce, SalesforceAuthenticationFailed
7
  from flask import Flask, jsonify, request, render_template, redirect, url_for
8
 
9
+ # Set up logging to capture errors and debug information
10
+ logging.basicConfig(level=logging.INFO)
 
 
 
 
 
11
  logger = logging.getLogger(__name__)
12
 
13
+ app = FastAPI()
 
 
14
 
15
+ # Salesforce credentials
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  SF_USERNAME = os.getenv("SF_USERNAME", "Ai@Coach.com")
17
  SF_PASSWORD = os.getenv("SF_PASSWORD", "Teja90325@")
18
  SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN", "clceSdBgQ30Rx9BSC66gAcRx")
19
  SF_DOMAIN = os.getenv("SF_DOMAIN", "login")
20
 
21
+ # Verify API key is set
22
+ API_KEY = os.getenv("HUGGING_FACE_API_KEY")
23
+ if not API_KEY:
24
+ logger.error("HUGGING_FACE_API_KEY environment variable not set")
25
+ raise ValueError("HUGGING_FACE_API_KEY environment variable not set")
26
+
27
+ # Connect to Salesforce
28
+ try:
29
+ sf = Salesforce(
30
+ username=SF_USERNAME,
31
+ password=SF_PASSWORD,
32
+ security_token=SF_SECURITY_TOKEN,
33
+ domain=SF_DOMAIN
34
+ )
35
+ logger.info("Successfully connected to Salesforce")
36
+ except Exception as e:
37
+ logger.error(f"Failed to connect to Salesforce: {str(e)}")
38
+ raise
39
+
40
+
41
+
42
 
43
  # Validate configuration
44
  if not HUGGING_FACE_API_TOKEN: