|
|
import gradio as gr |
|
|
from src.inference import predict_ticket |
|
|
|
|
|
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", {}) |
|
|
|
|
|
|
|
|
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" |
|
|
|
|
|
|
|
|
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() |
|
|
|