Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from inference import
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
)
|
| 16 |
|
| 17 |
if __name__ == "__main__":
|
| 18 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from src.inference import predict_ticket # ✅ Correct import
|
| 3 |
|
| 4 |
+
def predict_interface(ticket_text):
|
| 5 |
+
result = predict_ticket(ticket_text)
|
| 6 |
+
issue = result.get('issue_type', 'Unknown')
|
| 7 |
+
urgency = result.get('urgency_level', 'Unknown')
|
| 8 |
+
entities = result.get('entities', {})
|
| 9 |
|
| 10 |
+
entities_display = []
|
| 11 |
+
for key in ['products', 'dates', 'complaints']:
|
| 12 |
+
values = entities.get(key, [])
|
| 13 |
+
formatted_values = ', '.join(values) if values else 'None'
|
| 14 |
+
entities_display.append(f"{key.capitalize()}: {formatted_values}")
|
| 15 |
+
entities_str = "\n".join(entities_display)
|
| 16 |
+
|
| 17 |
+
return issue, urgency, entities_str
|
| 18 |
+
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=predict_interface,
|
| 21 |
+
inputs=gr.Textbox(
|
| 22 |
+
label="📝 Customer Support Ticket",
|
| 23 |
+
lines=6,
|
| 24 |
+
placeholder="Describe your issue clearly. Example: 'I returned the washing machine on 10th May but no refund received.'"
|
| 25 |
+
),
|
| 26 |
+
outputs=[
|
| 27 |
+
gr.Textbox(label="📌 Predicted Issue Type", lines=1),
|
| 28 |
+
gr.Textbox(label="⏱️ Predicted Urgency Level", lines=1),
|
| 29 |
+
gr.Textbox(label="🧠 Extracted Entities", lines=6)
|
| 30 |
+
],
|
| 31 |
+
title="📬 Customer Support Ticket Analyzer",
|
| 32 |
+
description=(
|
| 33 |
+
"Paste a customer support ticket. This tool uses ML to predict:\n"
|
| 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"
|
| 39 |
)
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
+
iface.launch()
|