ZennyKenny commited on
Commit
d5f54da
Β·
verified Β·
1 Parent(s): 5a7b2e0

remove visualizations for now

Browse files
Files changed (1) hide show
  1. app.py +0 -47
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  from transformers import pipeline
3
  import pandas as pd
4
  import spaces
5
- import plotly.express as px
6
 
7
  # Load dataset
8
  from datasets import load_dataset
@@ -39,40 +38,6 @@ def classify_comments(categories):
39
  df['comment_category'] = assigned_categories
40
  return df[['customer_id', 'customer_comment', 'comment_sentiment', 'comment_category', 'customer_nps', 'customer_segment']].to_html(index=False)
41
 
42
- def visualize_output():
43
- # Ensure the required columns exist
44
- if 'comment_sentiment' not in df.columns or 'comment_category' not in df.columns:
45
- return None, "Error: Please classify comments before visualizing."
46
-
47
- try:
48
- # Bar Chart of Sentiment by Category
49
- sentiment_by_category = df.groupby(['comment_category', 'comment_sentiment']).size().unstack()
50
- print("Sentiment by Category:")
51
- print(sentiment_by_category)
52
- bar_chart = px.bar(
53
- sentiment_by_category,
54
- barmode='stack',
55
- title="Sentiment by Comment Category",
56
- labels={'value': 'Count', 'comment_category': 'Category', 'comment_sentiment': 'Sentiment'}
57
- )
58
-
59
- # KPI Visualizations
60
- avg_nps = df['customer_nps'].mean()
61
- avg_nps_by_segment = df.groupby('customer_segment')['customer_nps'].mean().reset_index()
62
-
63
- kpi_visualization = f"""
64
- **Average NPS Scores:**
65
- - Overall: {avg_nps:.2f}
66
- **Average NPS by Segment:**
67
- {avg_nps_by_segment.to_markdown(index=False)}
68
- """
69
-
70
- return bar_chart, kpi_visualization
71
-
72
- except Exception as e:
73
- print(f"Error in visualize_output: {e}")
74
- return None, f"Error: {str(e)}"
75
-
76
  # Gradio Interface
77
  with gr.Blocks() as nps:
78
  # State to store categories
@@ -104,14 +69,6 @@ with gr.Blocks() as nps:
104
  classify_btn = gr.Button("Classify Comments")
105
  output = gr.HTML()
106
 
107
- # Visualize button
108
- visualize_btn = gr.Button("Visualize Output")
109
- sentiment_pie = gr.Plot(label="Sentiment Distribution")
110
- category_pie = gr.Plot(label="Comment Category Distribution")
111
- stacked_bar = gr.Plot(label="Sentiment by Comment Category")
112
- kpi_visualization = gr.Markdown()
113
- sentiment_by_segment_pie = gr.Plot(label="Sentiment by Customer Segment")
114
-
115
  # Function to load data from uploaded CSV
116
  def load_data(file):
117
  global df # Ensure we're modifying the global DataFrame
@@ -159,9 +116,5 @@ with gr.Blocks() as nps:
159
  inputs=categories,
160
  outputs=output
161
  )
162
- visualize_btn.click(
163
- fn=visualize_output,
164
- outputs=[sentiment_pie, category_pie, stacked_bar, kpi_visualization, sentiment_by_segment_pie]
165
- )
166
 
167
  nps.launch(share=True)
 
2
  from transformers import pipeline
3
  import pandas as pd
4
  import spaces
 
5
 
6
  # Load dataset
7
  from datasets import load_dataset
 
38
  df['comment_category'] = assigned_categories
39
  return df[['customer_id', 'customer_comment', 'comment_sentiment', 'comment_category', 'customer_nps', 'customer_segment']].to_html(index=False)
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  # Gradio Interface
42
  with gr.Blocks() as nps:
43
  # State to store categories
 
69
  classify_btn = gr.Button("Classify Comments")
70
  output = gr.HTML()
71
 
 
 
 
 
 
 
 
 
72
  # Function to load data from uploaded CSV
73
  def load_data(file):
74
  global df # Ensure we're modifying the global DataFrame
 
116
  inputs=categories,
117
  outputs=output
118
  )
 
 
 
 
119
 
120
  nps.launch(share=True)