Spaces:
Runtime error

ticket-summarizer / src /streamlit_app.py
Amit
updating summary balanced model
caacb60
Raw History Blame Contribute Delete
3.52 kB
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}`)")