Chia Woon Yap
Update app.py
cc08cc5 verified
# 1. INSTALL NECESSARY LIBRARIES
#!pip install -q transformers torch gradio pandas
import gradio as gr
import pandas as pd
from transformers import pipeline
import datetime
# 2. LOAD THE INTELLIGENCE ENGINE (Hugging Face)
# We use a Zero-Shot Classifier: It categorizes text WITHOUT needing prior training data.
print("Loading AI Model... Please wait.")
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
# 3. DEFINE THE DATA ENGINEERING LOGIC
def process_sales_lead(customer_name, company, interaction_text):
# Define our business categories (Targeting the Lead Scoring & Automation)
labels = ["Sales Opportunity", "Technical Support", "General Inquiry", "Urgent RFQ"]
# Run the AI Inference
result = classifier(interaction_text, labels)
top_intent = result['labels'][0]
confidence_score = round(result['scores'][0] * 100, 2)
# Logic for Lead Prioritization (The "Project Engineer" value-add)
priority = "LOW"
if top_intent in ["Sales Opportunity", "Urgent RFQ"] and confidence_score > 70:
priority = "HIGH"
elif confidence_score > 50:
priority = "MEDIUM"
# Create a fabricated record for the "Dashboard"
output_data = {
"Timestamp": datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
"Customer": customer_name,
"Company": company,
"Detected Intent": top_intent,
"AI Confidence (%)": confidence_score,
"Priority Level": priority
}
# Return formatted results for the UI
return f"Intent: {top_intent} ({confidence_score}%)", f"Priority: {priority}", output_data
# 4. BUILD THE GRADIO INTERFACE (The Proof of Concept)
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# 🚀 Sales Ops: AI Lead Scoring Hub")
gr.Markdown("### Proof of Concept: Automating Repetitive Manual Lead Triaging")
with gr.Row():
with gr.Column():
name = gr.Textbox(label="Customer Name", placeholder="e.g., John Doe")
company = gr.Textbox(label="Company", placeholder="e.g., TechCorp")
text = gr.TextArea(label="Interaction Text (Email/Log)",
placeholder="e.g., I need a quote for 500 units of the 5G connector...")
submit_btn = gr.Button("Analyze Lead", variant="primary")
with gr.Column():
intent_out = gr.Label(label="AI Analysis")
priority_out = gr.Textbox(label="System Priority Action")
json_out = gr.JSON(label="Cleaned Data for SAP/Salesforce Ingestion")
submit_btn.click(
fn=process_sales_lead,
inputs=[name, company, text],
outputs=[intent_out, priority_out, json_out]
)
# 5. LAUNCH THE POC
demo.launch(debug=True)