Spaces:
Runtime error

File size: 3,524 Bytes
34f3c6a
6d70056
 
 
 
75bbaf2
 
 
 
9b55d8f
 
 
b675746
 
 
9b55d8f
b675746
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b55d8f
75bbaf2
b675746
fea6e32
 
 
 
 
caacb60
7bf2f7c
fea6e32
 
 
 
 
9b55d8f
fea6e32
 
 
 
 
 
 
 
9b55d8f
fea6e32
9b55d8f
 
 
e50f971
 
9b55d8f
 
 
 
 
 
 
 
 
 
 
 
fea6e32
9b55d8f
fea6e32
 
 
 
9b55d8f
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import os
# βœ… Safe Hugging Face cache directory
os.environ["TRANSFORMERS_CACHE"] = "/tmp/hf_cache"
os.environ["HF_HOME"] = "/tmp/hf_cache"

import streamlit as st
from transformers import pipeline


# -------------------------------
# Optional: Human-readable routing label mapping
# -------------------------------
# -------------------------------
# Routing Classifier Label Map
# -------------------------------
LABEL_MAP = {
    "LABEL_0": "Cloud Infra SOC",
    "LABEL_1": "DES DW Ops",
    "LABEL_2": "DES EAI Ops",
    "LABEL_3": "DES EBSO Finance",
    "LABEL_4": "DES EBSO HR",
    "LABEL_5": "DES SAP Ops",
    "LABEL_6": "DES SFDC Admins",
    "LABEL_7": "DES Siebel Ops",
    "LABEL_8": "DES Web Ops",
    "LABEL_9": "ESE APPREL FC",
    "LABEL_10": "ESE BI Ops",
    "LABEL_11": "ESE Bigdata Operations Team",
    "LABEL_12": "ESE CEP OPS",
    "LABEL_13": "ESE Contact Center Ops",
    "LABEL_14": "ESE EBSO ALC",
    "LABEL_15": "ESE EBSO Customer Success",
    "LABEL_16": "ESE EBSO Finance Operations",
    "LABEL_17": "ESE EBSO Finance Team",
    "LABEL_18": "ESE EBSO Sales AKN IPG RCE",
    "LABEL_19": "ESE EDC OPS",
    "LABEL_20": "ESE PWS OPS",
    "LABEL_21": "ESE SAP Ops Team",
    "LABEL_22": "ESE SFDC Admins",
    "LABEL_23": "ESE SFDC Business Operations",
    "LABEL_24": "ESE SFDC Business Operations servicenow",
    "LABEL_25": "ESE Web Ops Team",
    "LABEL_26": "Service-Now ESE EBSO BSM",
    "LABEL_27": "Service-now - DES Bigdata Operations",
    "LABEL_28": "Service-now - DES Denodo Operations",
    "LABEL_29": "Service-now - ESE SDC SAP Business Operations",
    "LABEL_30": "base.accesssystems.ops",
    "LABEL_31": "ese-agentexp-ebso",
    "LABEL_32": "ese.ebso.nxm.support"
}


# -------------------------------
# Load models from Hugging Face
# -------------------------------
@st.cache_resource
def load_models():
    summarizer = pipeline("summarization", model="AmitBits/t5-summary-balanced-model")
    classifier = pipeline("text-classification", model="AmitBits/routing-classifier-balanced-model")
    return summarizer, classifier

summarizer, classifier = load_models()

# -------------------------------
# Streamlit UI Setup
# -------------------------------
st.set_page_config(page_title="Ticket Summarization & Routing", layout="wide")
st.title("🎫 Smart Ticket Summarizer & Router")

text_input = st.text_area("Enter your support ticket:", height=150)

if st.button("πŸ” Generate Summary & Route"):
    if not text_input.strip():
        st.warning("⚠️ Please enter a support ticket description.")
    else:
        with st.spinner("⏳ Processing..."):
            # Summary
            try:
                raw_summary = summarizer(text_input, max_length=64, min_length=10, do_sample=False)[0]["summary_text"]
                summary = raw_summary.split("[ROUTE]")[0].strip()
            except Exception as e:
                summary = f"❌ Error generating summary: {e}"

            # Routing
            try:
                prediction = classifier(text_input)[0]
                raw_label = prediction["label"]
                readable_label = LABEL_MAP.get(raw_label, raw_label)
                score = prediction["score"]
            except Exception as e:
                readable_label = "❌ Error classifying route"
                score = 0.0

        # Output
        st.subheader("βœ‚οΈ Summary")
        st.success(summary)

        st.subheader("πŸ“ Routing Department")
        st.info(f"**{readable_label}** (score: `{score:.2f}`)")