|
import gradio as gr |
|
from model import score_opportunity |
|
from datetime import datetime |
|
|
|
def predict_deal(amount, close_date, stage, industry, lead_score, emails_last_7_days, meetings_last_30_days): |
|
try: |
|
input_data = { |
|
"amount": amount, |
|
"close_date": close_date, |
|
"stage": stage, |
|
"industry": industry, |
|
"lead_score": lead_score, |
|
"emails_last_7_days": emails_last_7_days, |
|
"meetings_last_30_days": meetings_last_30_days |
|
} |
|
|
|
result = score_opportunity(input_data) |
|
|
|
score = result["score"] |
|
confidence = result["confidence"] |
|
|
|
if score >= 80 and confidence >= 0.85: |
|
recommendation = "β
Great potential. Proceed confidently with the deal." |
|
risk = "Low" |
|
elif 60 <= score < 80: |
|
if confidence >= 0.75: |
|
recommendation = "π‘ Moderate chance. Strengthen customer engagement." |
|
risk = "Medium" |
|
else: |
|
recommendation = "π€ 50/50. Customer interest is unclear. Clarify further." |
|
risk = "Medium" |
|
elif score < 60 and (emails_last_7_days + meetings_last_30_days) >= 5: |
|
recommendation = "π Investigate β engagement high, but low interest shown." |
|
risk = "High" |
|
else: |
|
recommendation = "β οΈ Low potential. Reassess or de-prioritize." |
|
risk = "High" |
|
|
|
return score, confidence, risk, recommendation |
|
except Exception as e: |
|
return 0, 0.0, "Error", f"Error: {str(e)}" |
|
|
|
demo = gr.Interface( |
|
fn=predict_deal, |
|
inputs=[ |
|
gr.Number(label="π° Deal Amount"), |
|
gr.Textbox(label="π
Close Date (YYYY-MM-DD)"), |
|
gr.Dropdown( |
|
["Prospecting", "Qualification", "Proposal/Price Quote", "Negotiation/Review", "Closed Won", "Closed Lost"], |
|
label="π Stage" |
|
), |
|
gr.Textbox(label="π Industry"), |
|
gr.Slider(0, 100, step=1, label="π Lead Score"), |
|
gr.Number(label="βοΈ Emails in Last 7 Days"), |
|
gr.Number(label="π
Meetings in Last 30 Days"), |
|
], |
|
outputs=[ |
|
gr.Number(label="β
Score"), |
|
gr.Number(label="π Confidence"), |
|
gr.Textbox(label="β οΈ Risk"), |
|
gr.Textbox(label="π€ Recommendation"), |
|
], |
|
title="AI Deal Qualification Engine", |
|
description="Enter opportunity details to get deal score, confidence level, risk, and AI recommendation." |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|