Sanjayraju30's picture
Update app.py
1c48b85 verified
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()