Spaces:
Running
on
Zero
Running
on
Zero
support dynamic categories
Browse files
app.py
CHANGED
@@ -28,7 +28,9 @@ def classify_comments():
|
|
28 |
results = []
|
29 |
for comment in df['customer_comment']:
|
30 |
sentiment = classifier(comment)[0]['label']
|
31 |
-
|
|
|
|
|
32 |
category = generator(prompt, max_length=30)[0]['generated_text']
|
33 |
categories.append(category)
|
34 |
sentiments.append(sentiment)
|
@@ -38,6 +40,14 @@ def classify_comments():
|
|
38 |
|
39 |
# Gradio Interface
|
40 |
with gr.Blocks() as nps:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
uploaded_file = gr.File(label="Upload CSV", type="filepath")
|
42 |
template_btn = gr.Button("Use Template")
|
43 |
gr.Markdown("# NPS Comment Categorization")
|
@@ -64,6 +74,6 @@ with gr.Blocks() as nps:
|
|
64 |
|
65 |
uploaded_file.change(fn=load_data, inputs=uploaded_file, outputs=output)
|
66 |
template_btn.click(fn=lambda: "Using Template Dataset", outputs=output)
|
67 |
-
classify_btn.click(fn=classify_comments, outputs=output)
|
68 |
|
69 |
nps.launch()
|
|
|
28 |
results = []
|
29 |
for comment in df['customer_comment']:
|
30 |
sentiment = classifier(comment)[0]['label']
|
31 |
+
category_list = [box.value for box in category_boxes if box.value.strip() != '']
|
32 |
+
category_str = ', '.join([cat.strip() for cat in category_list])
|
33 |
+
prompt = f"What category best describes this comment? '{comment}' Please answer using only the name of the category: {category_str}."
|
34 |
category = generator(prompt, max_length=30)[0]['generated_text']
|
35 |
categories.append(category)
|
36 |
sentiments.append(sentiment)
|
|
|
40 |
|
41 |
# Gradio Interface
|
42 |
with gr.Blocks() as nps:
|
43 |
+
def add_category():
|
44 |
+
new_box = gr.Textbox(label="Category", placeholder="Enter a category")
|
45 |
+
category_boxes.append(new_box)
|
46 |
+
return new_box
|
47 |
+
|
48 |
+
add_category_btn.click(fn=add_category, outputs=category_boxes)
|
49 |
+
category_boxes = [] # Store category input boxes
|
50 |
+
add_category_btn = gr.Button("Add Category")
|
51 |
uploaded_file = gr.File(label="Upload CSV", type="filepath")
|
52 |
template_btn = gr.Button("Use Template")
|
53 |
gr.Markdown("# NPS Comment Categorization")
|
|
|
74 |
|
75 |
uploaded_file.change(fn=load_data, inputs=uploaded_file, outputs=output)
|
76 |
template_btn.click(fn=lambda: "Using Template Dataset", outputs=output)
|
77 |
+
classify_btn.click(fn=classify_comments, inputs=[category_input], outputs=output)
|
78 |
|
79 |
nps.launch()
|