Spaces:
Running
on
Zero
Running
on
Zero
import gradio as gr | |
from transformers import pipeline | |
import pandas as pd | |
# Load the dataset | |
from datasets import load_dataset | |
ds = load_dataset('ZennyKenny/demo_customer_nps') | |
df = pd.DataFrame(ds['train']) | |
# Initialize the model pipeline | |
from huggingface_hub import login | |
import os | |
# Login using the API key stored as an environment variable | |
hf_api_key = os.getenv("API_KEY") | |
login(token=hf_api_key) | |
pipe = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english") | |
# Function to classify customer comments | |
def classify_comments(): | |
results = [] | |
for comment in df['customer_comment']: | |
prompt = comment | |
category = pipe(prompt)[0]['label'] | |
results.append(category) | |
df['comment_category'] = results | |
return df[['customer_comment', 'comment_category']].to_html(index=False) | |
# Gradio Interface | |
with gr.Blocks() as nps: | |
gr.Markdown("# NPS Comment Categorization") | |
classify_btn = gr.Button("Classify Comments") | |
output = gr.HTML() | |
classify_btn.click(fn=classify_comments, outputs=output) | |
nps.launch() | |