ZennyKenny commited on
Commit
278f543
Β·
verified Β·
1 Parent(s): bf3b2cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -23
app.py CHANGED
@@ -38,6 +38,39 @@ def classify_comments(categories):
38
  df['comment_category'] = assigned_categories
39
  return df.to_html(index=False) # Return all fields with appended sentiment and category
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  # Gradio Interface
42
  with gr.Blocks() as nps:
43
  # App title
@@ -78,29 +111,6 @@ with gr.Blocks() as nps:
78
  # Output
79
  output = gr.HTML()
80
 
81
- # Function to load data from uploaded CSV
82
- def load_data(file):
83
- global df # Ensure we're modifying the global DataFrame
84
- if file is not None:
85
- file.seek(0) # Reset file pointer
86
- if file.name.endswith('.csv'):
87
- custom_df = pd.read_csv(file, encoding='utf-8')
88
- else:
89
- return "Error: Uploaded file is not a CSV."
90
- # Check for required columns
91
- required_columns = ['customer_comment']
92
- if not all(col in custom_df.columns for col in required_columns):
93
- return f"Error: Uploaded CSV must contain the following column: {', '.join(required_columns)}"
94
- df = custom_df
95
- return "Custom CSV loaded successfully!"
96
- else:
97
- return "No file uploaded."
98
-
99
- # Function to use template categories
100
- def use_template():
101
- template_categories = ["Product Experience", "Customer Support", "Price of Service", "Other"]
102
- return template_categories, f"**Categories:**\n" + "\n".join([f"- {cat}" for cat in template_categories])
103
-
104
  # Event handlers
105
  add_category_btn.click(
106
  fn=add_category,
 
38
  df['comment_category'] = assigned_categories
39
  return df.to_html(index=False) # Return all fields with appended sentiment and category
40
 
41
+ # Function to add a category
42
+ def add_category(categories, new_category):
43
+ if new_category.strip() != "" and len(categories) < 5: # Limit to 5 categories
44
+ categories.append(new_category.strip())
45
+ return categories, "", f"**Categories:**\n" + "\n".join([f"- {cat}" for cat in categories])
46
+
47
+ # Function to reset categories
48
+ def reset_categories():
49
+ return [], "**Categories:**\n- None"
50
+
51
+ # Function to load data from uploaded CSV
52
+ def load_data(file):
53
+ global df # Ensure we're modifying the global DataFrame
54
+ if file is not None:
55
+ file.seek(0) # Reset file pointer
56
+ if file.name.endswith('.csv'):
57
+ custom_df = pd.read_csv(file, encoding='utf-8')
58
+ else:
59
+ return "Error: Uploaded file is not a CSV."
60
+ # Check for required columns
61
+ required_columns = ['customer_comment']
62
+ if not all(col in custom_df.columns for col in required_columns):
63
+ return f"Error: Uploaded CSV must contain the following column: {', '.join(required_columns)}"
64
+ df = custom_df
65
+ return "Custom CSV loaded successfully!"
66
+ else:
67
+ return "No file uploaded."
68
+
69
+ # Function to use template categories
70
+ def use_template():
71
+ template_categories = ["Product Experience", "Customer Support", "Price of Service", "Other"]
72
+ return template_categories, f"**Categories:**\n" + "\n".join([f"- {cat}" for cat in template_categories])
73
+
74
  # Gradio Interface
75
  with gr.Blocks() as nps:
76
  # App title
 
111
  # Output
112
  output = gr.HTML()
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  # Event handlers
115
  add_category_btn.click(
116
  fn=add_category,