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()