Update app.py
Browse files
app.py
CHANGED
@@ -5,52 +5,64 @@ from insights import explain_score
|
|
5 |
from logger import log_submission
|
6 |
|
7 |
def run_engine(amount, stage, industry, emails, meetings, close_gap, feedback=""):
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
with gr.Blocks(title="AI Deal Qualification Engine") as app:
|
26 |
-
gr.Markdown("
|
27 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
amount = gr.Number(label="Deal Amount (USD)", value=50000)
|
31 |
-
stage = gr.Dropdown(["Prospecting", "Proposal/Price Quote", "Negotiation", "Closed Won", "Closed Lost"], label="Stage")
|
32 |
-
industry = gr.Textbox(label="Industry", value="Software")
|
33 |
|
34 |
-
|
35 |
-
emails = gr.Number(label="Emails in Last 7 Days", value=3)
|
36 |
-
meetings = gr.Number(label="Meetings in Last 30 Days", value=2)
|
37 |
-
close_gap = gr.Number(label="Days Until Close Date", value=14)
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
|
42 |
-
|
|
|
43 |
|
44 |
-
|
45 |
-
lead_score_out = gr.Number(label="Lead Score (Generated)", interactive=False)
|
46 |
-
ai_score_out = gr.Number(label="AI Score (0β100)", interactive=False)
|
47 |
-
confidence_out = gr.Number(label="Confidence", interactive=False)
|
48 |
-
risk_out = gr.Textbox(label="Risk Level")
|
49 |
-
reco_out = gr.Textbox(label="AI Recommendation")
|
50 |
-
explain_out = gr.Textbox(label="AI Explanation")
|
51 |
|
52 |
-
submit.click(
|
53 |
-
|
54 |
-
|
|
|
|
|
55 |
|
56 |
-
app.launch()
|
|
|
5 |
from logger import log_submission
|
6 |
|
7 |
def run_engine(amount, stage, industry, emails, meetings, close_gap, feedback=""):
|
8 |
+
try:
|
9 |
+
lead_score = get_lead_score(stage, emails, meetings, close_gap, amount)
|
10 |
+
ai_score = calculate_score(lead_score, emails, meetings, close_gap, amount)
|
11 |
+
confidence = calculate_confidence(ai_score)
|
12 |
+
risk = calculate_risk(ai_score, confidence, emails, meetings)
|
13 |
+
recommendation = generate_recommendation(stage, emails, meetings, risk)
|
14 |
+
explanation = explain_score(lead_score, ai_score, confidence, risk, stage, close_gap, emails, meetings)
|
15 |
+
|
16 |
+
log_submission({
|
17 |
+
"amount": amount, "stage": stage, "industry": industry,
|
18 |
+
"emails": emails, "meetings": meetings, "gap": close_gap,
|
19 |
+
"lead_score": lead_score, "score": ai_score, "confidence": confidence,
|
20 |
+
"risk": risk, "feedback": feedback
|
21 |
+
})
|
22 |
+
|
23 |
+
return lead_score, ai_score, confidence, risk, recommendation, explanation
|
24 |
+
|
25 |
+
except Exception as e:
|
26 |
+
return 0, 0, 0.0, "Error", "N/A", f"Error occurred: {str(e)}"
|
27 |
|
28 |
with gr.Blocks(title="AI Deal Qualification Engine") as app:
|
29 |
+
gr.Markdown("## π€ AI-Powered Deal Qualification Engine")
|
30 |
+
gr.Markdown("Intelligently qualify sales deals using engagement and pipeline signals.")
|
31 |
+
|
32 |
+
with gr.Tab("π₯ Input"):
|
33 |
+
with gr.Row():
|
34 |
+
amount = gr.Number(label="π° Deal Amount (USD)", value=50000)
|
35 |
+
stage = gr.Dropdown(
|
36 |
+
["Prospecting", "Proposal/Price Quote", "Negotiation", "Closed Won", "Closed Lost"],
|
37 |
+
label="π Stage"
|
38 |
+
)
|
39 |
+
industry = gr.Textbox(label="π Industry", value="Software")
|
40 |
+
|
41 |
+
with gr.Row():
|
42 |
+
emails = gr.Number(label="βοΈ Emails (Last 7 Days)", value=3)
|
43 |
+
meetings = gr.Number(label="π
Meetings (Last 30 Days)", value=2)
|
44 |
+
close_gap = gr.Number(label="π Days Until Close", value=14)
|
45 |
|
46 |
+
feedback = gr.Textbox(label="π¬ Optional: Rep Feedback", placeholder="Add any qualitative insights...")
|
|
|
|
|
|
|
47 |
|
48 |
+
submit = gr.Button("π Run AI Scoring")
|
|
|
|
|
|
|
49 |
|
50 |
+
with gr.Tab("π Results"):
|
51 |
+
with gr.Accordion("AI Scoring Output", open=True):
|
52 |
+
lead_score_out = gr.Number(label="π’ Lead Score", interactive=False)
|
53 |
+
ai_score_out = gr.Number(label="π AI Score (0β100)", interactive=False)
|
54 |
+
confidence_out = gr.Number(label="π Confidence", interactive=False)
|
55 |
|
56 |
+
risk_out = gr.Textbox(label="β οΈ Risk Level", lines=1, interactive=False)
|
57 |
+
reco_out = gr.Textbox(label="π‘ AI Recommendation", lines=2, interactive=False)
|
58 |
+
explain_out = gr.Textbox(label="π§ Explanation", lines=5, interactive=False)
|
59 |
|
60 |
+
status = gr.Markdown("") # Optional status or error message
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
submit.click(
|
63 |
+
fn=run_engine,
|
64 |
+
inputs=[amount, stage, industry, emails, meetings, close_gap, feedback],
|
65 |
+
outputs=[lead_score_out, ai_score_out, confidence_out, risk_out, reco_out, explain_out]
|
66 |
+
)
|
67 |
|
68 |
+
app.launch(share=False)
|