import gradio as gr from model import score_opportunity def predict_deal(amount, close_date, stage, industry, lead_score, emails_last_7_days, meetings_last_30_days): result = score_opportunity({ "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 }) 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": score, "Confidence": confidence, "Risk": risk, "Recommendation": recommendation } 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 and recommendation." ) if __name__ == "__main__": demo.launch()