ZennyKenny commited on
Commit
4530b74
Β·
verified Β·
1 Parent(s): 52d8051
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -1,20 +1,29 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
- from datasets import load_dataset
4
  import pandas as pd
5
 
6
- # Load the dataset from Hugging Face
 
 
7
  ds = load_dataset('ZennyKenny/demo_customer_nps')
8
  df = pd.DataFrame(ds['train'])
9
 
10
  # Initialize the model pipeline
 
 
 
 
 
 
 
11
  pipe = pipeline("text-generation", model="mistralai/Mistral-Small-24B-Base-2501")
12
 
13
  # Function to classify customer comments
 
14
  def classify_comments():
15
  results = []
16
  for comment in df['customer_comment']:
17
- prompt = f"Classify this customer feedback: '{comment}' into one of five categories."
18
  category = pipe(prompt, max_length=30)[0]['generated_text']
19
  results.append(category)
20
  df['comment_category'] = results
 
1
  import gradio as gr
2
  from transformers import pipeline
 
3
  import pandas as pd
4
 
5
+ # Load the dataset
6
+ DATASET_URL = 'https://huggingface.co/datasets/ZennyKenny/demo_customer_nps/resolve/main/customer_feedback_dataset.csv'
7
+ from datasets import load_dataset
8
  ds = load_dataset('ZennyKenny/demo_customer_nps')
9
  df = pd.DataFrame(ds['train'])
10
 
11
  # Initialize the model pipeline
12
+ from huggingface_hub import login
13
+ import os
14
+
15
+ # Login using the API key stored as an environment variable
16
+ hf_api_key = os.getenv("API_KEY")
17
+ login(token=hf_api_key)
18
+
19
  pipe = pipeline("text-generation", model="mistralai/Mistral-Small-24B-Base-2501")
20
 
21
  # Function to classify customer comments
22
+ @spaces.GPU
23
  def classify_comments():
24
  results = []
25
  for comment in df['customer_comment']:
26
+ prompt = f"Classify this customer feedback: '{comment}' into one of the following categories: Price of Service, Quality of Customer Support, Product Experience. Please only respond with the category name and nothing else."
27
  category = pipe(prompt, max_length=30)[0]['generated_text']
28
  results.append(category)
29
  df['comment_category'] = results