Spaces:
Sleeping
Sleeping
| # app.py | |
| # Telecom Customer Complaint Classification and Routing App | |
| # Using Hugging Face Transformers + Gradio | |
| from transformers import pipeline | |
| import gradio as gr | |
| # Load zero-shot classification model | |
| classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli") | |
| # Complaint categories | |
| categories = [ | |
| "Network Issue", | |
| "Billing Issue", | |
| "SIM Issue", | |
| "Recharge Issue", | |
| "Device Issue" | |
| ] | |
| # Mapping categories to routing teams | |
| routing_teams = { | |
| "Network Issue": "Network Operations", | |
| "Billing Issue": "Billing Support", | |
| "SIM Issue": "SIM Support", | |
| "Recharge Issue": "Payments Team", | |
| "Device Issue": "Technical Support" | |
| } | |
| # Function to classify complaint | |
| def classify_complaint(complaint_text): | |
| if not complaint_text.strip(): | |
| return "No input provided", "0.0%", "N/A" | |
| result = classifier(complaint_text, candidate_labels=categories) | |
| top_category = result['labels'][0] | |
| confidence_score = result['scores'][0] | |
| suggested_team = routing_teams.get(top_category, "General Support") | |
| confidence_percent = f"{confidence_score*100:.2f}%" | |
| return top_category, confidence_percent, suggested_team | |
| # Build Gradio UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## ๐ Telecom Customer Complaint Classification and Routing") | |
| gr.Markdown("Enter a customer complaint below to get category, confidence, and routing team.") | |
| with gr.Row(): | |
| complaint_input = gr.Textbox(label="Customer Complaint", placeholder="Type your complaint here...", lines=4) | |
| submit_btn = gr.Button("Submit") | |
| with gr.Row(): | |
| category_output = gr.Textbox(label="Predicted Category") | |
| confidence_output = gr.Textbox(label="Confidence Score") | |
| team_output = gr.Textbox(label="Suggested Routing Team") | |
| submit_btn.click( | |
| classify_complaint, | |
| inputs=complaint_input, | |
| outputs=[category_output, confidence_output, team_output] | |
| ) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| demo.launch() |