ZennyKenny commited on
Commit
ea5a489
Β·
verified Β·
1 Parent(s): 0a5100e

Support custom upload

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -27,7 +27,6 @@ def classify_comments():
27
  categories = []
28
  results = []
29
  for comment in df['customer_comment']:
30
- # Classify the sentiment first
31
  sentiment = classifier(comment)[0]['label']
32
  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."
33
  category = generator(prompt, max_length=30)[0]['generated_text']
@@ -39,10 +38,25 @@ def classify_comments():
39
 
40
  # Gradio Interface
41
  with gr.Blocks() as nps:
 
 
42
  gr.Markdown("# NPS Comment Categorization")
43
  classify_btn = gr.Button("Classify Comments")
44
  output = gr.HTML()
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  classify_btn.click(fn=classify_comments, outputs=output)
47
 
48
  nps.launch()
 
27
  categories = []
28
  results = []
29
  for comment in df['customer_comment']:
 
30
  sentiment = classifier(comment)[0]['label']
31
  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."
32
  category = generator(prompt, max_length=30)[0]['generated_text']
 
38
 
39
  # Gradio Interface
40
  with gr.Blocks() as nps:
41
+ uploaded_file = gr.File(label="Upload CSV", file_types=["csv"], optional=True)
42
+ template_btn = gr.Button("Use Template")
43
  gr.Markdown("# NPS Comment Categorization")
44
  classify_btn = gr.Button("Classify Comments")
45
  output = gr.HTML()
46
 
47
+ def load_data(file):
48
+ if file is not None:
49
+ custom_df = pd.read_csv(file.name)
50
+ if 'customer_comment' not in custom_df.columns:
51
+ return "Error: Uploaded CSV must contain a column named 'customer_comment'"
52
+ global df
53
+ df = custom_df
54
+ return "Custom CSV loaded successfully!"
55
+ else:
56
+ return "No file uploaded."
57
+
58
+ uploaded_file.change(fn=load_data, inputs=uploaded_file, outputs=output)
59
+ template_btn.click(fn=lambda: "Using Template Dataset", outputs=output)
60
  classify_btn.click(fn=classify_comments, outputs=output)
61
 
62
  nps.launch()