Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
|
|
2 |
from transformers import pipeline
|
3 |
import nltk
|
4 |
|
5 |
-
# Download NLTK data for sentence tokenization
|
6 |
nltk.download('punkt_tab')
|
7 |
|
8 |
# Load the Hugging Face pipelines
|
@@ -12,6 +12,9 @@ sentiment_analyzer = pipeline("sentiment-analysis", model="SarahMakk/CustomModel
|
|
12 |
# Define the categories for customer feedback
|
13 |
CATEGORIES = ["Pricing", "Feature", "Customer Service", "Delivery", "Quality"]
|
14 |
|
|
|
|
|
|
|
15 |
# Streamlit app UI
|
16 |
st.title("Customer Feedback Categorization with Sentiment Analysis")
|
17 |
st.markdown(
|
@@ -20,6 +23,7 @@ st.markdown(
|
|
20 |
and determine the sentiment (positive or negative) for each relevant category.
|
21 |
A single feedback may belong to multiple categories, such as Pricing, Feature, and Customer Service.
|
22 |
The feedback is split into sentences, and each sentence is categorized and analyzed for sentiment.
|
|
|
23 |
"""
|
24 |
)
|
25 |
|
@@ -31,16 +35,6 @@ feedback_input = st.text_area(
|
|
31 |
value="I was shocked to see the price tag on this new gadget—it’s way too expensive for what it offers, especially compared to competitors! Despite the issues I faced with my order, the customer service team's effort to rectify the situation was commendable, though their follow-up could have used some improvement for full satisfaction."
|
32 |
)
|
33 |
|
34 |
-
# Confidence threshold for zero-shot classification
|
35 |
-
threshold = st.slider(
|
36 |
-
"Confidence Threshold",
|
37 |
-
min_value=0.0,
|
38 |
-
max_value=1.0,
|
39 |
-
value=0.2,
|
40 |
-
step=0.05,
|
41 |
-
help="Categories with scores above this threshold will be displayed."
|
42 |
-
)
|
43 |
-
|
44 |
# Classify button
|
45 |
if st.button("Classify Feedback"):
|
46 |
if not feedback_input.strip():
|
@@ -62,7 +56,7 @@ if st.button("Classify Feedback"):
|
|
62 |
|
63 |
# Get categories with scores above the threshold
|
64 |
for label, score in zip(classification_result["labels"], classification_result["scores"]):
|
65 |
-
if score >=
|
66 |
# Perform sentiment analysis on the sentence
|
67 |
sentiment_result = sentiment_analyzer(sentence)
|
68 |
sentiment_label = sentiment_result[0]["label"]
|
@@ -91,4 +85,4 @@ if st.button("Classify Feedback"):
|
|
91 |
st.write("") # Add a blank line for readability
|
92 |
|
93 |
if not found_categories:
|
94 |
-
st.warning("No categories
|
|
|
2 |
from transformers import pipeline
|
3 |
import nltk
|
4 |
|
5 |
+
# Download NLTK data for sentence tokenization
|
6 |
nltk.download('punkt_tab')
|
7 |
|
8 |
# Load the Hugging Face pipelines
|
|
|
12 |
# Define the categories for customer feedback
|
13 |
CATEGORIES = ["Pricing", "Feature", "Customer Service", "Delivery", "Quality"]
|
14 |
|
15 |
+
# Define the fixed confidence threshold
|
16 |
+
CONFIDENCE_THRESHOLD = 0.8
|
17 |
+
|
18 |
# Streamlit app UI
|
19 |
st.title("Customer Feedback Categorization with Sentiment Analysis")
|
20 |
st.markdown(
|
|
|
23 |
and determine the sentiment (positive or negative) for each relevant category.
|
24 |
A single feedback may belong to multiple categories, such as Pricing, Feature, and Customer Service.
|
25 |
The feedback is split into sentences, and each sentence is categorized and analyzed for sentiment.
|
26 |
+
Only categories with a confidence score >= 0.8 are displayed.
|
27 |
"""
|
28 |
)
|
29 |
|
|
|
35 |
value="I was shocked to see the price tag on this new gadget—it’s way too expensive for what it offers, especially compared to competitors! Despite the issues I faced with my order, the customer service team's effort to rectify the situation was commendable, though their follow-up could have used some improvement for full satisfaction."
|
36 |
)
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
# Classify button
|
39 |
if st.button("Classify Feedback"):
|
40 |
if not feedback_input.strip():
|
|
|
56 |
|
57 |
# Get categories with scores above the threshold
|
58 |
for label, score in zip(classification_result["labels"], classification_result["scores"]):
|
59 |
+
if score >= CONFIDENCE_THRESHOLD:
|
60 |
# Perform sentiment analysis on the sentence
|
61 |
sentiment_result = sentiment_analyzer(sentence)
|
62 |
sentiment_label = sentiment_result[0]["label"]
|
|
|
85 |
st.write("") # Add a blank line for readability
|
86 |
|
87 |
if not found_categories:
|
88 |
+
st.warning("No categories met the confidence threshold of 0.8.")
|