ZennyKenny commited on
Commit
bf3b2cd
Β·
verified Β·
1 Parent(s): 3b076ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -20
app.py CHANGED
@@ -40,33 +40,42 @@ def classify_comments(categories):
40
 
41
  # Gradio Interface
42
  with gr.Blocks() as nps:
43
- # State to store categories
44
- categories = gr.State([])
45
 
46
- # Function to add a category
47
- def add_category(categories, new_category):
48
- if new_category.strip() != "" and len(categories) < 5: # Limit to 5 categories
49
- categories.append(new_category.strip())
50
- return categories, "", f"**Categories:**\n" + "\n".join([f"- {cat}" for cat in categories])
 
51
 
52
- # Function to reset categories
53
- def reset_categories():
54
- return [], "**Categories:**\n- None"
55
-
56
- # UI for adding categories
57
  with gr.Row():
58
- category_input = gr.Textbox(label="New Category", placeholder="Enter category name")
59
- add_category_btn = gr.Button("Add Category")
60
- reset_btn = gr.Button("Reset Categories")
61
- category_status = gr.Markdown("**Categories:**\n- None")
 
 
 
 
62
 
63
- # File upload and template buttons
64
- uploaded_file = gr.File(label="Upload CSV", type="filepath")
65
  template_btn = gr.Button("Use Template")
66
- gr.Markdown("# NPS Comment Categorization")
 
 
 
 
 
 
 
67
 
68
  # Classify button
69
- classify_btn = gr.Button("Classify Comments")
 
 
70
  output = gr.HTML()
71
 
72
  # Function to load data from uploaded CSV
 
40
 
41
  # Gradio Interface
42
  with gr.Blocks() as nps:
43
+ # App title
44
+ gr.Markdown("# Customer Comment Classifier")
45
 
46
+ # Short explanation
47
+ gr.Markdown("""
48
+ This app classifies customer comments into categories and assigns sentiment labels (Positive/Negative).
49
+ You can upload your own dataset or use the provided template. The app will append the generated
50
+ `comment_sentiment` and `comment_category` fields to your dataset.
51
+ """)
52
 
53
+ # File upload and instructions
 
 
 
 
54
  with gr.Row():
55
+ with gr.Column(scale=1):
56
+ uploaded_file = gr.File(label="Upload CSV", type="filepath", scale=1)
57
+ with gr.Column(scale=2):
58
+ gr.Markdown("""
59
+ **Instructions:**
60
+ - Upload a CSV file with at least one column: `customer_comment`.
61
+ - If you don't have your own data, click **Use Template** to load a sample dataset.
62
+ """)
63
 
64
+ # Template button
 
65
  template_btn = gr.Button("Use Template")
66
+
67
+ # Category widgets
68
+ with gr.Row():
69
+ with gr.Column():
70
+ category_input = gr.Textbox(label="New Category", placeholder="Enter category name")
71
+ add_category_btn = gr.Button("Add Category")
72
+ reset_btn = gr.Button("Reset Categories")
73
+ category_status = gr.Markdown("**Categories:**\n- None")
74
 
75
  # Classify button
76
+ classify_btn = gr.Button("Classify", size="sm")
77
+
78
+ # Output
79
  output = gr.HTML()
80
 
81
  # Function to load data from uploaded CSV