File size: 1,740 Bytes
249e14b fdf044d 249e14b cc07f68 fdf044d 249e14b fdf044d cc07f68 fdf044d cc07f68 fdf044d cc07f68 fdf044d cc07f68 fdf044d cc07f68 fdf044d cc07f68 fdf044d cc07f68 249e14b cc07f68 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import gradio as gr
from src.inference import predict_ticket # Uses the fixed inference.py with nltk fix
def predict_interface(ticket_text):
try:
result = predict_ticket(ticket_text)
issue = result.get("issue_type", "Unknown")
urgency = result.get("urgency_level", "Unknown")
entities = result.get("entities", {})
# Format entity output
lines = []
for key in ["products", "dates", "complaints"]:
vals = entities.get(key, [])
lines.append(f"{key.capitalize()}: {', '.join(vals) if vals else 'None'}")
entities_str = "\n".join(lines)
return issue, urgency, entities_str
except Exception as e:
return f"Prediction error: {str(e)}", "Prediction error", "Prediction error"
# Build the Gradio interface
iface = gr.Interface(
fn=predict_interface,
inputs=gr.Textbox(
label="📝 Customer Support Ticket",
lines=6,
placeholder=(
"Describe your issue clearly.\n"
"Example: 'I returned the washing machine on 10th May but no refund received.'"
)
),
outputs=[
gr.Textbox(label="📌 Predicted Issue Type"),
gr.Textbox(label="⏱️ Predicted Urgency Level"),
gr.Textbox(label="🧠 Extracted Entities"),
],
title="📬 Customer Support Ticket Analyzer",
description=(
"Paste a customer support ticket. This tool uses machine learning to predict:\n\n"
"- 📌 Issue Type (e.g., Late Delivery, Refund)\n"
"- ⏱️ Urgency Level (Low / Medium / High)\n"
"- 🧠 Extracted Entities (Products, Dates, Complaints)"
),
allow_flagging="never"
)
if __name__ == "__main__":
iface.launch()
|