Spaces:
Running
on
Zero
Running
on
Zero
add category output
Browse files
app.py
CHANGED
@@ -16,18 +16,24 @@ import os
|
|
16 |
hf_api_key = os.getenv("API_KEY")
|
17 |
login(token=hf_api_key)
|
18 |
|
19 |
-
|
|
|
20 |
|
21 |
# Function to classify customer comments
|
22 |
-
@spaces.GPU
|
23 |
def classify_comments():
|
|
|
|
|
24 |
results = []
|
25 |
for comment in df['customer_comment']:
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# Gradio Interface
|
33 |
with gr.Blocks() as nps:
|
|
|
16 |
hf_api_key = os.getenv("API_KEY")
|
17 |
login(token=hf_api_key)
|
18 |
|
19 |
+
classifier = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
|
20 |
+
generator = pipeline("text-generation", model="mrm8488/t5-base-finetuned-question-generation-ap")
|
21 |
|
22 |
# Function to classify customer comments
|
|
|
23 |
def classify_comments():
|
24 |
+
sentiments = []
|
25 |
+
categories = []
|
26 |
results = []
|
27 |
for comment in df['customer_comment']:
|
28 |
+
# Classify the sentiment first
|
29 |
+
sentiment = pipe(comment)[0]['label']
|
30 |
+
prompt = f"What category best describes this comment? '{comment}' Please answer using only the name of the category: Product Experience, Customer Support, Price of Service, Other."
|
31 |
+
category = generator(prompt, max_length=30)[0]['generated_text']
|
32 |
+
categories.append(category)
|
33 |
+
sentiments.append(sentiment)
|
34 |
+
df['comment_sentiment'] = sentiments
|
35 |
+
df['comment_category'] = categories
|
36 |
+
return df[['customer_comment', 'comment_sentiment', 'comment_category']].to_html(index=False)
|
37 |
|
38 |
# Gradio Interface
|
39 |
with gr.Blocks() as nps:
|