Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,58 +10,41 @@ import matplotlib.pyplot as plt
|
|
| 10 |
import plotly.express as px
|
| 11 |
from PIL import Image
|
| 12 |
|
| 13 |
-
# Define categories
|
| 14 |
categories_keywords = {
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 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 |
-
"Account Management": ["login", "account", "new account", "create account", "log out", "google", "access"],
|
| 38 |
-
"Order Status": ["order", "status", "tracking", "shipment", "delivery", "purchase", "dispatch"],
|
| 39 |
-
"Miscellaneous": ["miscellaneous", "other", "various", "random", "general", "unknown", "unsorted"]
|
| 40 |
-
|
| 41 |
}
|
| 42 |
|
| 43 |
-
# Initialize
|
| 44 |
|
| 45 |
def categorize_question(question):
|
| 46 |
-
# Split the question into words
|
| 47 |
-
words = question.split()
|
| 48 |
-
|
| 49 |
-
# Check if the question has only one word
|
| 50 |
-
if len(words) == 1:
|
| 51 |
-
single_word = words[0].lower()
|
| 52 |
-
# Check if the single word is in the Start of Conversation category
|
| 53 |
-
if any(single_word in keyword for keyword in categories_keywords["Start of Conversation"]):
|
| 54 |
-
return "Start of Conversation"
|
| 55 |
-
else:
|
| 56 |
-
return "End of Conversation"
|
| 57 |
-
|
| 58 |
-
# General categorization based on multiple words
|
| 59 |
for category, keywords in categories_keywords.items():
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
def preprocess_data(df
|
| 65 |
df.rename(columns={'Question Asked': 'texts'}, inplace=True)
|
| 66 |
df['texts'] = df['texts'].astype(str).str.lower()
|
| 67 |
df['texts'] = df['texts'].apply(lambda text: re.sub(r'https?://\S+|www\.\S+', '', text))
|
|
@@ -112,7 +95,8 @@ def preprocess_data(df, categories_keywords):
|
|
| 112 |
df['texts'] = df['texts'].str.strip()
|
| 113 |
df = df[df['texts'] != '']
|
| 114 |
|
| 115 |
-
|
|
|
|
| 116 |
|
| 117 |
return df
|
| 118 |
|
|
@@ -154,6 +138,7 @@ def generate_wordcloud(df):
|
|
| 154 |
return img
|
| 155 |
|
| 156 |
def generate_bar_chart(df, num_clusters_to_display):
|
|
|
|
| 157 |
common_words = {'i', 'you', 'thanks', 'thank', 'ok', 'okay', 'sure', 'done'}
|
| 158 |
|
| 159 |
top_categories = df['Category'].value_counts().index[:num_clusters_to_display]
|
|
|
|
| 10 |
import plotly.express as px
|
| 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 |
|
| 33 |
def categorize_question(question):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
for category, keywords in categories_keywords.items():
|
| 35 |
+
for keyword in keywords:
|
| 36 |
+
if keyword.lower() in question.lower():
|
| 37 |
+
# Check if the question is one word and belongs to 'End of Conversation'
|
| 38 |
+
if category == 'End of Conversation':
|
| 39 |
+
return category
|
| 40 |
+
# If not 'End of Conversation', return the matched category
|
| 41 |
+
if category != 'End of Conversation':
|
| 42 |
+
return category
|
| 43 |
+
return 'Miscellaneous'
|
| 44 |
+
|
| 45 |
+
|
| 46 |
|
| 47 |
+
def preprocess_data(df):
|
| 48 |
df.rename(columns={'Question Asked': 'texts'}, inplace=True)
|
| 49 |
df['texts'] = df['texts'].astype(str).str.lower()
|
| 50 |
df['texts'] = df['texts'].apply(lambda text: re.sub(r'https?://\S+|www\.\S+', '', text))
|
|
|
|
| 95 |
df['texts'] = df['texts'].str.strip()
|
| 96 |
df = df[df['texts'] != '']
|
| 97 |
|
| 98 |
+
# Categorize the texts
|
| 99 |
+
df['Category'] = df['texts'].apply(categorize_question)
|
| 100 |
|
| 101 |
return df
|
| 102 |
|
|
|
|
| 138 |
return img
|
| 139 |
|
| 140 |
def generate_bar_chart(df, num_clusters_to_display):
|
| 141 |
+
# Exclude common words from the top words
|
| 142 |
common_words = {'i', 'you', 'thanks', 'thank', 'ok', 'okay', 'sure', 'done'}
|
| 143 |
|
| 144 |
top_categories = df['Category'].value_counts().index[:num_clusters_to_display]
|