Update app.py
Browse files
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 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
|
15 |
-
|
16 |
-
confidence = result["confidence"]
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
else:
|
26 |
-
recommendation = "
|
27 |
-
risk = "
|
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 |
-
|
36 |
-
|
37 |
-
"
|
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(
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
gr.
|
|
|
|
|
|
|
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__":
|