Sanjayraju30 commited on
Commit
2a09313
ยท
verified ยท
1 Parent(s): 449011e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -43
app.py CHANGED
@@ -1,57 +1,64 @@
1
- # app.py
2
-
3
  import gradio as gr
4
  from model import score_opportunity
5
- from utils import validate_data
6
 
7
- def predict_deal(amount, stage, industry, lead_score, emails_last_7_days, meetings_last_30_days):
8
- input_data = {
9
  "amount": amount,
 
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
- if not validate_data(input_data):
18
- return 0, 0.0, "Invalid", "โš ๏ธ Please enter all fields correctly."
19
-
20
- result = score_opportunity(input_data)
21
- return result['score'], result['confidence'], result['risk'], result['recommendation']
22
 
23
- with gr.Blocks(title="AI Deal Qualification Engine") as demo:
24
- gr.Markdown("""
25
- # ๐Ÿค– AI-Powered Deal Qualification Engine
26
- _Predict B2B deal success using AI-based scoring._
27
- """)
28
 
29
- with gr.Row():
30
- with gr.Column():
31
- amount = gr.Number(label="๐Ÿ’ฐ Deal Amount (INR/USD)")
32
- stage = gr.Dropdown(
33
- ["Prospecting", "Qualified", "Proposal", "Proposal/Price Quote", "Negotiation", "Closed Won", "Closed Lost"],
34
- label="๐Ÿ“Š Deal Stage"
35
- )
36
- industry = gr.Textbox(label="๐Ÿญ Industry")
 
 
 
 
 
 
 
 
37
 
38
- with gr.Column():
39
- lead_score = gr.Number(label="๐Ÿ“ˆ Lead Score (0โ€“100)")
40
- emails_last_7_days = gr.Number(label="โœ‰๏ธ Emails in Last 7 Days")
41
- meetings_last_30_days = gr.Number(label="๐Ÿ“… Meetings in Last 30 Days")
42
-
43
- submit_btn = gr.Button("๐Ÿ” Predict")
44
-
45
- with gr.Row():
46
- score = gr.Number(label="๐Ÿงฎ Score (0โ€“100)", interactive=False)
47
- confidence = gr.Number(label="๐Ÿ“Š Confidence (0โ€“1)", interactive=False)
48
- risk = gr.Textbox(label="๐Ÿšฆ Risk Level", interactive=False)
49
- recommendation = gr.Textbox(label="๐Ÿง  Recommendation", lines=2, interactive=False)
50
 
51
- submit_btn.click(
52
- fn=predict_deal,
53
- inputs=[amount, stage, industry, lead_score, emails_last_7_days, meetings_last_30_days],
54
- outputs=[score, confidence, risk, recommendation]
55
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- demo.launch()
 
 
 
 
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__":
64
+ demo.launch()