karthikmn commited on
Commit
6ec8c25
Β·
verified Β·
1 Parent(s): 47c609d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -27
app.py CHANGED
@@ -1,39 +1,51 @@
1
  import gradio as gr
 
 
 
 
2
  from scorer import get_lead_score, calculate_score, calculate_confidence, calculate_risk
3
  from recommender import generate_recommendation
4
  from insights import explain_score
5
  from logger import log_submission
6
 
7
- from simple_salesforce import Salesforce
8
- from dotenv import load_dotenv
9
- import os
10
 
11
- # Get the Salesforce credentials from environment variables
12
  sf_username = os.getenv("SF_USERNAME")
13
  sf_password = os.getenv("SF_PASSWORD")
14
  sf_security_token = os.getenv("SF_SECURITY_TOKEN")
15
- sf_instance_url = os.getenv("SF_INSTANCE_URL")
16
-
17
- # Data mapped to your Qualification_Engine__c fields
18
- data = {
19
- "Deal_Amount__c": amount, # πŸ’° Deal Amount
20
- "Stage__c": stage, # πŸ“Š Deal Stage
21
- "Industry__c": industry, # 🏭 Industry
22
- "Emails_7_Days__c": emails, # βœ‰οΈ Emails in last 7 days
23
- "Meetings_30_Days__c": meetings, # πŸ“… Meetings in last 30 days
24
- "Days_Until_Close__c": close_gap, # πŸ“† Days Until Close
25
- "Rep_Feedback__c": feedback, # πŸ’¬ Rep Feedback
26
- "Lead_Score__c": lead_score, # πŸ”’ Lead Score
27
- "AI_Score__c": ai_score, # 🌟 AI Score
28
- "Confidence__c": confidence, # πŸ“ Confidence %
29
- "Risk_Level__c": risk, # ⚠️ Risk Level
30
- "AI_Recommendation__c": recommendation, # πŸ’‘ AI Recommendation
31
- "Explanation__c": explanation # 🧠 Explanation
32
- }
33
-
34
- # Creating the record in Salesforce
35
- response = sf.qualification_engine__c.create(data)
36
-
 
 
 
 
 
 
 
 
 
37
  def run_engine(amount, stage, industry, emails, meetings, close_gap, feedback=""):
38
  try:
39
  lead_score = get_lead_score(stage, emails, meetings, close_gap, amount)
@@ -63,6 +75,10 @@ def run_engine(amount, stage, industry, emails, meetings, close_gap, feedback=""
63
  except Exception as e:
64
  return 0, 0, 0.0, "Error", "N/A", f"Error occurred: {str(e)}", f"❌ Error: {str(e)}"
65
 
 
 
 
 
66
  with gr.Blocks(title="AI Deal Qualification Engine") as app:
67
  gr.Markdown("## πŸ€– AI-Powered Deal Qualification Engine")
68
  gr.Markdown("Intelligently qualify sales deals using engagement and pipeline signals.")
@@ -103,4 +119,4 @@ with gr.Blocks(title="AI Deal Qualification Engine") as app:
103
  outputs=[lead_score_out, ai_score_out, confidence_out, risk_out, reco_out, explain_out, status]
104
  )
105
 
106
- app.launch(share=False)
 
1
  import gradio as gr
2
+ import os
3
+ from dotenv import load_dotenv
4
+ from simple_salesforce import Salesforce
5
+
6
  from scorer import get_lead_score, calculate_score, calculate_confidence, calculate_risk
7
  from recommender import generate_recommendation
8
  from insights import explain_score
9
  from logger import log_submission
10
 
11
+ # Load env variables
12
+ load_dotenv()
 
13
 
14
+ # Salesforce credentials
15
  sf_username = os.getenv("SF_USERNAME")
16
  sf_password = os.getenv("SF_PASSWORD")
17
  sf_security_token = os.getenv("SF_SECURITY_TOKEN")
18
+ sf_domain = os.getenv("SF_DOMAIN", "login") # default to production
19
+
20
+ # Connect to Salesforce
21
+ sf = Salesforce(
22
+ username=sf_username,
23
+ password=sf_password,
24
+ security_token=sf_security_token,
25
+ domain=sf_domain
26
+ )
27
+
28
+ def push_to_salesforce(data: dict) -> str:
29
+ try:
30
+ response = sf.Qualification_Engine__c.create({
31
+ "Deal_Amount__c": data.get("amount"),
32
+ "Stage__c": data.get("stage"),
33
+ "Industry__c": data.get("industry"),
34
+ "Emails_7_Days__c": data.get("emails"),
35
+ "Meetings_30_Days__c": data.get("meetings"),
36
+ "Days_Until_Close__c": data.get("gap"),
37
+ "Rep_Feedback__c": data.get("feedback"),
38
+ "Lead_Score__c": data.get("lead_score"),
39
+ "AI_Score__c": data.get("score"),
40
+ "Confidence__c": data.get("confidence"),
41
+ "Risk_Level__c": data.get("risk"),
42
+ "AI_Recommendation__c": data.get("recommendation"),
43
+ "Explanation__c": data.get("explanation")
44
+ })
45
+ return f"βœ… Pushed to Salesforce with ID: {response['id']}"
46
+ except Exception as e:
47
+ return f"❌ Salesforce Error: {str(e)}"
48
+
49
  def run_engine(amount, stage, industry, emails, meetings, close_gap, feedback=""):
50
  try:
51
  lead_score = get_lead_score(stage, emails, meetings, close_gap, amount)
 
75
  except Exception as e:
76
  return 0, 0, 0.0, "Error", "N/A", f"Error occurred: {str(e)}", f"❌ Error: {str(e)}"
77
 
78
+ # Read share flag from env
79
+ share_app = os.getenv("GRADIO_SHARE", "false").lower() == "true"
80
+
81
+ # Gradio UI
82
  with gr.Blocks(title="AI Deal Qualification Engine") as app:
83
  gr.Markdown("## πŸ€– AI-Powered Deal Qualification Engine")
84
  gr.Markdown("Intelligently qualify sales deals using engagement and pipeline signals.")
 
119
  outputs=[lead_score_out, ai_score_out, confidence_out, risk_out, reco_out, explain_out, status]
120
  )
121
 
122
+ app.launch(share=share_app)