Update app.py
Browse files
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 |
-
|
8 |
-
|
9 |
-
import os
|
10 |
|
11 |
-
#
|
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 |
-
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
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=
|
|
|
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)
|