Sanjayraju30 commited on
Commit
1c48b85
Β·
verified Β·
1 Parent(s): 48d9182

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -44
app.py CHANGED
@@ -1,63 +1,67 @@
1
  import gradio as gr
2
  from model import score_opportunity
 
3
 
4
  def predict_deal(amount, close_date, stage, industry, lead_score, emails_last_7_days, meetings_last_30_days):
5
- result = score_opportunity({
6
- "amount": amount,
7
- "close_date": close_date,
8
- "stage": stage,
9
- "industry": industry,
10
- "lead_score": lead_score,
11
- "emails_last_7_days": emails_last_7_days,
12
- "meetings_last_30_days": meetings_last_30_days
13
- })
 
14
 
15
- score = result["score"]
16
- confidence = result["confidence"]
17
 
18
- if score >= 80 and confidence >= 0.85:
19
- recommendation = "βœ… Great potential. Proceed confidently with the deal."
20
- risk = "Low"
21
- elif 60 <= score < 80:
22
- if confidence >= 0.75:
23
- recommendation = "🟑 Moderate chance. Strengthen customer engagement."
24
- risk = "Medium"
 
 
 
 
 
 
 
 
 
25
  else:
26
- recommendation = "πŸ€” 50/50. Customer interest is unclear. Clarify further."
27
- risk = "Medium"
28
- elif score < 60 and (emails_last_7_days + meetings_last_30_days) >= 5:
29
- recommendation = "πŸ” Investigate – engagement high, but low interest shown."
30
- risk = "High"
31
- else:
32
- recommendation = "⚠️ Low potential. Reassess or de-prioritize."
33
- risk = "High"
34
 
35
- return {
36
- "Score": score,
37
- "Confidence": confidence,
38
- "Risk": risk,
39
- "Recommendation": recommendation
40
- }
41
 
42
  demo = gr.Interface(
43
  fn=predict_deal,
44
  inputs=[
45
- gr.Number(label="Deal Amount"),
46
- gr.Textbox(label="Close Date (YYYY-MM-DD)"),
47
- gr.Dropdown(["Prospecting", "Qualification", "Proposal/Price Quote", "Negotiation/Review", "Closed Won", "Closed Lost"], label="Stage"),
48
- gr.Textbox(label="Industry"),
49
- gr.Slider(0, 100, step=1, label="Lead Score"),
50
- gr.Number(label="Emails in Last 7 Days"),
51
- gr.Number(label="Meetings in Last 30 Days"),
 
 
 
52
  ],
53
  outputs=[
54
- gr.Number(label="Score"),
55
- gr.Number(label="Confidence"),
56
- gr.Textbox(label="Risk"),
57
- gr.Textbox(label="Recommendation"),
58
  ],
59
  title="AI Deal Qualification Engine",
60
- description="Enter opportunity details to get deal score and recommendation."
61
  )
62
 
63
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  from model import score_opportunity
3
+ from datetime import datetime
4
 
5
  def predict_deal(amount, close_date, stage, industry, lead_score, emails_last_7_days, meetings_last_30_days):
6
+ try:
7
+ input_data = {
8
+ "amount": amount,
9
+ "close_date": close_date,
10
+ "stage": stage,
11
+ "industry": industry,
12
+ "lead_score": lead_score,
13
+ "emails_last_7_days": emails_last_7_days,
14
+ "meetings_last_30_days": meetings_last_30_days
15
+ }
16
 
17
+ result = score_opportunity(input_data)
 
18
 
19
+ score = result["score"]
20
+ confidence = result["confidence"]
21
+
22
+ if score >= 80 and confidence >= 0.85:
23
+ recommendation = "βœ… Great potential. Proceed confidently with the deal."
24
+ risk = "Low"
25
+ elif 60 <= score < 80:
26
+ if confidence >= 0.75:
27
+ recommendation = "🟑 Moderate chance. Strengthen customer engagement."
28
+ risk = "Medium"
29
+ else:
30
+ recommendation = "πŸ€” 50/50. Customer interest is unclear. Clarify further."
31
+ risk = "Medium"
32
+ elif score < 60 and (emails_last_7_days + meetings_last_30_days) >= 5:
33
+ recommendation = "πŸ” Investigate – engagement high, but low interest shown."
34
+ risk = "High"
35
  else:
36
+ recommendation = "⚠️ Low potential. Reassess or de-prioritize."
37
+ risk = "High"
 
 
 
 
 
 
38
 
39
+ return score, confidence, risk, recommendation
40
+ except Exception as e:
41
+ return 0, 0.0, "Error", f"Error: {str(e)}"
 
 
 
42
 
43
  demo = gr.Interface(
44
  fn=predict_deal,
45
  inputs=[
46
+ gr.Number(label="πŸ’° Deal Amount"),
47
+ gr.Textbox(label="πŸ“… Close Date (YYYY-MM-DD)"),
48
+ gr.Dropdown(
49
+ ["Prospecting", "Qualification", "Proposal/Price Quote", "Negotiation/Review", "Closed Won", "Closed Lost"],
50
+ label="πŸ“Š Stage"
51
+ ),
52
+ gr.Textbox(label="🏭 Industry"),
53
+ gr.Slider(0, 100, step=1, label="πŸ“ˆ Lead Score"),
54
+ gr.Number(label="βœ‰οΈ Emails in Last 7 Days"),
55
+ gr.Number(label="πŸ“… Meetings in Last 30 Days"),
56
  ],
57
  outputs=[
58
+ gr.Number(label="βœ… Score"),
59
+ gr.Number(label="πŸ“Š Confidence"),
60
+ gr.Textbox(label="⚠️ Risk"),
61
+ gr.Textbox(label="πŸ€– Recommendation"),
62
  ],
63
  title="AI Deal Qualification Engine",
64
+ description="Enter opportunity details to get deal score, confidence level, risk, and AI recommendation."
65
  )
66
 
67
  if __name__ == "__main__":