tanish78 commited on
Commit
2d8cb02
·
verified ·
1 Parent(s): 0348d93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -41
app.py CHANGED
@@ -11,31 +11,22 @@ import plotly.express as px
11
  from PIL import Image
12
 
13
  categories_keywords = {
14
- "Application Status": ["application status", "application", "status", "submitted", "processing", "pending", "approval", "rejected", "accepted"],
15
- "Volunteering": ["volunteer", "volunteering", "help out", "assist", "volunteer work", "volunteer opportunities"],
16
- "Certificates": ["certificate", "certificates", "completion", "certification", "accreditation", "proof", "document", "certified"],
17
- "Job Opportunities": ["job", "opportunity", "career", "vacancy", "position", "employment", "hiring", "recruitment", "internship"],
18
- "Surveys and Forms": ["survey", "form", "forms", "questionnaire", "feedback form", "response", "fill out", "submission"],
19
- "General Queries": ["hello", "hi", "help", "general", "query", "question", "info", "information", "inquiry", "ask"],
20
- "Spam": ["spam", "subscribe", "remove", "stop", "junk", "block", "opt-out", "watch my video", "click on this link", "win prize"],
21
- "Rescheduling and Postponing": ["reschedule", "postpone", "delay", "change date", "new time", "rearrange", "shift", "adjust timing"],
22
- "Contact and Communication Issues": ["contact", "communicate", "communication", "reach out", "phone", "email", "address", "details"],
23
- "Email and Credentials Issues": ["email", "credentials", "login", "password", "access", "username", "account", "verification", "reset"],
24
- "Timing and Scheduling": ["timing", "schedule", "scheduling", "time", "appointment", "availability", "calendar", "book", "slot"],
25
- "Salary and Benefits": ["salary", "benefits", "pay", "compensation", "wages", "earnings", "package", "remuneration", "incentives"],
26
- "Technical Issues": ["technical", "issue", "problem", "error", "bug", "glitch", "fix", "troubleshoot", "support"],
27
- "End of Conversation": ["bye", "thank you", "thanks", "goodbye", "see you", "later", "end", "close", "sign off"],
28
- "Start of Conversation": ["start", "begin", "hello", "hi", "initiate", "greet", "greeting", "open", "commence"],
29
- "Feedback": ["feedback", "comments", "review", "opinion", "suggestion", "critique", "rating"],
30
- "Online Meetings": ["meeting", "meeting code", "passcode", "join meeting", "zoom", "zoom link"],
31
- "Event Inquiries": ["event", "webinar", "meeting", "conference", "session", "seminar", "workshop", "invitation"],
32
- "Payment Issues": ["payment", "billing", "transaction", "charge", "fee", "invoice", "refund", "receipt"],
33
- "Registration Issues": ["registration", "register", "sign up", "enroll", "join", "signup", "enrollment"],
34
- "Service Requests": ["service", "support", "request", "assistance", "help", "aid", "maintenance"],
35
- "Account Issues": ["account", "profile", "update", "activation", "deactivation", "credentials", "reset"],
36
- "Product Information": ["product", "service", "details", "info", "information", "specifications", "features"],
37
- "Order Status": ["order", "status", "tracking", "shipment", "delivery", "purchase", "dispatch"],
38
- "Miscellaneous": []
39
  }
40
 
41
 
@@ -169,43 +160,41 @@ def generate_bar_chart(df, num_clusters_to_display):
169
  img = Image.open(buf)
170
  return img
171
 
172
- def main(file, num_categories_to_display):
173
  try:
174
  df = pd.read_csv(file)
175
 
 
 
176
 
177
  df = preprocess_data(df)
178
-
179
- df = df[df['Category'] != 'Miscellaneous']
180
 
181
- # Get category sizes and sort by size in descending order
182
  category_sizes = df['Category'].value_counts().reset_index()
183
  category_sizes.columns = ['Category', 'Count']
184
- sorted_categories = category_sizes.sort_values(by='Count', ascending=False)['Category'].tolist()
185
- sorted_categories_sm = category_sizes.sort_values(by='Count', ascending=True)['Category'].tolist()
186
-
187
 
188
- # Get the largest x categories as specified by num_categories_to_display
189
- largest_categories = sorted_categories[:num_categories_to_display]
190
- smallest_categories = sorted_categories_sm[:num_categories_to_display]
191
 
192
  # Filter the dataframe to include only the largest categories
193
  filtered_df = df[df['Category'].isin(largest_categories)]
194
- filtered_cloud_df = df[df['Category'].isin(smallest_categories)]
195
 
196
  # Sort the dataframe by Category
197
  filtered_df = filtered_df.sort_values(by='Category')
198
- filtered_cloud_df = filtered_cloud_df.sort_values(by='Category')
199
 
200
- wordcloud_img = generate_wordcloud(filtered_cloud_df) # Word cloud based on the entire dataframe
201
- bar_chart_img = generate_bar_chart(df, num_categories_to_display) # Bar chart based on the filtered dataframe
202
 
203
  with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as tmpfile:
204
  filtered_df.to_csv(tmpfile.name, index=False)
 
 
 
 
205
  print(f"Error: {e}")
206
  return str(e), None, None
207
 
208
-
209
  interface = gr.Interface(
210
  fn=main,
211
  inputs=[
@@ -222,4 +211,3 @@ interface = gr.Interface(
222
  )
223
 
224
  interface.launch(share=True)
225
-
 
11
  from PIL import Image
12
 
13
  categories_keywords = {
14
+ 'Application Status': ['application', 'applied', 'update on my application', 'result of my application', 'selected', 'selection process', 'apply', 'fellow', 'lesson plan', 'status of my application', 'application update', 'application status', 'applied for'],
15
+ 'Volunteering': ['volunteering', 'volunteer', 'volunteering certificate', 'resume my volunteering', 'volunteering journey', 'volunteering with TFI', 'volunteering opportunities', 'volunteer work', 'volunteer program'],
16
+ 'Certificates': ['certificate', 'certificates', 'certificate of completion', 'volunteer certificate', 'issue certificate'],
17
+ 'Job Opportunities': ['job', 'vacancy', 'Talent Acquisition Executive job', 'opportunity', 'job opening', 'job position', 'career opportunities'],
18
+ 'Surveys and Forms': ['survey', 'form', 'fill out the survey', 'application form', 'survey link', 'survey form', 'form submission'],
19
+ 'General Queries': ['query', 'queries', 'questions', 'feedback', 'loved', 'overwhelming', 'general question', 'inquiry', 'query about'],
20
+ 'Spam': ['free recharge', 'offer', 'click the link', 'https'],
21
+ 'Rescheduling and Postponing': ['reschedule', 'postpone', 'cancellation', 'date', 'time slot', 'change date', 'change time', 'reschedule appointment'],
22
+ 'Contact and Communication Issues': ['call', 'phone', 'contact', 'not received', 'contact support', 'phone call', 'call back', 'internet'],
23
+ 'Email and Credentials Issues': ['email', 'credentials', 'received', 'email issue', 'email problem', 'credential issue', 'login problem'],
24
+ 'Timing and Scheduling': ['session', 'time', 'interview', 'baje', 'schedule time', 'meeting time', 'appointment time'],
25
+ 'Salary and Benefits': ['salary', 'increment', 'accommodation', 'training period', 'reside', 'stipend', 'pay', 'wage', 'salary details', 'benefits information'],
26
+ 'Technical Issues': ['network issues', 'zoom meeting', 'passcode', 'technical', 'issue','technical problem', 'system issue', 'technical support'],
27
+ 'Complaint Handling': ['help', 'i need help', 'Help me', 'complaint', 'issue is unresolved', 'unsatisfied', 'bad experience'],
28
+ 'End of Conversation': ['thanks', 'thankss', 'thank u', 'thank you', 'ok', 'okay', 'done', 'joining', 'sounds good', 'goodbye', 'end chat', 'end'],
29
+ 'Miscellaneous': []
 
 
 
 
 
 
 
 
 
30
  }
31
 
32
 
 
160
  img = Image.open(buf)
161
  return img
162
 
163
+ def main(file, num_clusters_to_display):
164
  try:
165
  df = pd.read_csv(file)
166
 
167
+ # Filter by 'Fallback Message shown'
168
+ df = df[df['Answer'] == 'Fallback Message shown']
169
 
170
  df = preprocess_data(df)
 
 
171
 
172
+ # Get category sizes and sort by size in ascending order
173
  category_sizes = df['Category'].value_counts().reset_index()
174
  category_sizes.columns = ['Category', 'Count']
175
+ sorted_categories = category_sizes.sort_values(by='Count', ascending=True)['Category'].tolist()
 
 
176
 
177
+ # Get the largest x categories as specified by num_clusters_to_display
178
+ largest_categories = sorted_categories[:num_clusters_to_display]
 
179
 
180
  # Filter the dataframe to include only the largest categories
181
  filtered_df = df[df['Category'].isin(largest_categories)]
 
182
 
183
  # Sort the dataframe by Category
184
  filtered_df = filtered_df.sort_values(by='Category')
 
185
 
186
+ wordcloud_img = generate_wordcloud(filtered_df)
187
+ bar_chart_img = generate_bar_chart(filtered_df, num_clusters_to_display)
188
 
189
  with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as tmpfile:
190
  filtered_df.to_csv(tmpfile.name, index=False)
191
+ csv_file_path = tmpfile.name
192
+
193
+ return csv_file_path, wordcloud_img, bar_chart_img
194
+ except Exception as e:
195
  print(f"Error: {e}")
196
  return str(e), None, None
197
 
 
198
  interface = gr.Interface(
199
  fn=main,
200
  inputs=[
 
211
  )
212
 
213
  interface.launch(share=True)