Satyam0077 commited on
Commit
fdf044d
Β·
verified Β·
1 Parent(s): 681ecc1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -18
app.py CHANGED
@@ -1,38 +1,46 @@
1
  import gradio as gr
2
- from src.inference import predict_ticket # Now points to the corrected inference.py
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
- # Format entity output
11
- lines = []
12
- for key in ["products", "dates", "complaints"]:
13
- vals = entities.get(key, [])
14
- lines.append(f"{key.capitalize()}: {', '.join(vals) if vals else 'None'}")
15
- entities_str = "\n".join(lines)
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"
 
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"