karthikmn commited on
Commit
577c50a
Β·
verified Β·
1 Parent(s): acb9352

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -40
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
- lead_score = get_lead_score(stage, emails, meetings, close_gap, amount)
9
- ai_score = calculate_score(lead_score, emails, meetings, close_gap, amount)
10
- confidence = calculate_confidence(ai_score)
11
- risk = calculate_risk(ai_score, confidence, emails, meetings)
12
- recommendation = generate_recommendation(stage, emails, meetings, risk)
13
- explanation = explain_score(lead_score, ai_score, confidence, risk, stage, close_gap, emails, meetings)
14
-
15
- # Simulate logging (can be extended to DB)
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
  with gr.Blocks(title="AI Deal Qualification Engine") as app:
26
- gr.Markdown("# πŸ€– AI-Powered Deal Qualification Engine")
27
- gr.Markdown("Score deals intelligently using pipeline stage, engagement, and timing.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
- with gr.Row():
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
- with gr.Row():
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
- feedback = gr.Textbox(label="Optional: Rep Feedback")
 
 
 
 
40
 
41
- with gr.Row():
42
- submit = gr.Button("Run AI Scoring")
 
43
 
44
- with gr.Accordion("πŸ“Š Results", open=True):
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(fn=run_engine,
53
- inputs=[amount, stage, industry, emails, meetings, close_gap, feedback],
54
- outputs=[lead_score_out, ai_score_out, confidence_out, risk_out, reco_out, explain_out])
 
 
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)