Update app.py
Browse files
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 |
-
|
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 |
-
|
24 |
-
|
25 |
-
# ๐ค AI-Powered Deal Qualification Engine
|
26 |
-
_Predict B2B deal success using AI-based scoring._
|
27 |
-
""")
|
28 |
|
29 |
-
|
30 |
-
with
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
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 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
-
|
|
|
|
|
|
|
|
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()
|