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