diff --git a/User-Query-Portal-Superstore/Employee Details.json b/User-Query-Portal-Superstore/Employee Details.json new file mode 100644 index 0000000..b22bb63 --- /dev/null +++ b/User-Query-Portal-Superstore/Employee Details.json @@ -0,0 +1,58 @@ +[ + { + "Name ":"Mr. Dinesh Sahu", + "Department ":"Sales Department", + "Support ":"Shipping and Delivery", + "Phone Number ":9685743214, + "Email Id ": "dineshsahu3456@gmail.com" + }, + { + "Name ":"Mrs. Nandini Anand", + "Department ":"Sales Department", + "Support ":"General Assistance", + "Phone Number ":9685743232, + "Email Id ": "anandnandini3456@gmail.com" + }, + { + "Name ":"Mr. Shaurya Shrivastava", + "Department ":"Technical Department", + "Support ":"Service Inquiry", + "Phone Number ":9685743233, + "Email Id ": "shauryas2002@gmail.com" + }, + { + "Name ":"Mr. Sandeep Singh", + "Department ":"Technical Department", + "Support ":"Technical Support", + "Phone Number ":9685743210, + "Email Id ": "sandeepsingh1234@gmail.com" + }, + { + "Name ":"Mr. Raghunandan Verma", + "Department ":"Customer Service", + "Support ":"Information Request", + "Phone Number ":9685743250, + "Email Id ": "raghunandanv3456@gmail.com" + }, + { + "Name ":"Mr. Jayawardhan Rajagopal", + "Department ":"Customer Service", + "Support ":"Information Request", + "Phone Number ":9685743299, + "Email Id ": "jayawardhanrajgopal3456@gmail.com" + }, + { + "Name ":"Mr. Sriman Narayana", + "Department ":"Sales Department", + "Support ":"Product Inquiry", + "Phone Number ":9685743299, + "Email Id ": "srimannarayana@gmail.com" + }, + { + "Name ":"Mr. Jayaraj", + "Department ":"Technical Department", + "Support ":"Account Assistance", + "Phone Number ":9685743298, + "Email Id ": "jayaraj3490@gmail.com" + } +] \ No newline at end of file diff --git a/User-Query-Portal-Superstore/Intent Recognition.py b/User-Query-Portal-Superstore/Intent Recognition.py new file mode 100644 index 0000000..de67c76 --- /dev/null +++ b/User-Query-Portal-Superstore/Intent Recognition.py @@ -0,0 +1,209 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[1]: + + +import pandas as pd +import difflib +from sklearn.feature_extraction.text import TfidfVectorizer +from sklearn.metrics.pairwise import cosine_similarity +from nltk.tokenize import RegexpTokenizer + + +# In[2]: + + +data = pd.read_excel('Jobs.xlsx') +data.head() + + +# In[3]: + + +# removing punctuations from the query of the customer +tokenizer = RegexpTokenizer(r'\w+') +data['Query of the Customer'] = data['Query of the Customer'].apply(lambda x: ' '.join(tokenizer.tokenize(x))) + + +# In[4]: + + +# combining all the column's data into a single feature to use it for processing of the queries +combine_feat = data['Query of the Customer'] + ' ' + data['Query Type'] + ' ' + data['Who Can Help'] +combine_feat + + +# In[5]: + + +# to vectorize the features + +vectorizer = TfidfVectorizer() +feature_vectors = vectorizer.fit_transform(combine_feat) + + +# In[6]: + + +# similarity scores +similarity = cosine_similarity(feature_vectors) + + +# In[7]: + + +print(similarity) + + +# In[8]: + + +# taking user input as query +query = input('Enter your query : ') + + +# In[9]: + + +# putting all the queries into one list +list_of_all_queries =data['Query of the Customer'].tolist() +list_of_all_queries + + +# In[10]: + + +# finding closest match to user input from the list of all queries + +find_close_match = difflib.get_close_matches(query, list_of_all_queries) +find_close_match + + +# In[11]: + + +close_match = find_close_match[0] +close_match + + +# In[12]: + + +#index of the closest match +index_of_the_query = data[data['Query of the Customer'] == close_match]['index'].values[0] +index_of_the_query + + +# In[13]: + + +# checking similarity with every query in the dataset + +similarity_score = list(enumerate(similarity[index_of_the_query])) +similarity_score + + +# In[14]: + + +len(similarity_score) + + +# In[15]: + + +#sorting the similarity score list +sorted_similarity_score = sorted(similarity_score, key = lambda x:x[1], reverse = True) +print(sorted_similarity_score) + + +# In[16]: + + +print('Your query is related to : \n') + +i = 1 + +query_of_the_user = list() + +for query1 in sorted_similarity_score: + index = query1[0] + query_of_the_user.append(data[data.index==index]['Query Type'].values[0]) + +print(query_of_the_user) + +# for name in query_type: +# print(name) + + +# In[17]: + + +print('Your query is related to : ') +# Set to store unique elements encountered so far +query_type = set() +i = 0 +# Iterate over the list and print only those elements that are not in the set +for word in query_of_the_user: + if word not in query_type: + print(word) + query_type.add(word) + i+=1 + + if i>=3: + break + + +# ### Fetching the details from json file to help the user contact the necessary support + +# In[18]: + + +import json + +def find_details(query_1): + + # Load the JSON data from the file + with open("Employee Details.json", "r") as f: + data = json.load(f) + + # Find employees with matching support + matching_details = [] + for details in data: + if query_1.lower() in details["Support "].lower(): + matching_details.append(details) + + return matching_details + + +# In[20]: + + +query_1 = query_of_the_user[0] +matching_details = find_details(query_1) + +print("USER's Query : ") +print(query) +print("Query related to : ",query_of_the_user[0]) +print("="*50) +print("Please contanct the following person for help : ") +print("="*50) +if matching_details: + # Print employee information + for employee in matching_details: + print(f"Employee Name: {employee['Name ']}") + print(f"Department: {employee['Department ']}") + print(f"Support: {employee['Support ']}") + print(f"Phone Number: {employee['Phone Number ']}") + print(f"Email: {employee['Email Id ']}") + print("-" * 20) +else: + print("No matching employees found.") + + +# In[ ]: + + + + diff --git a/User-Query-Portal-Superstore/Jobs.xlsx b/User-Query-Portal-Superstore/Jobs.xlsx new file mode 100644 index 0000000..7df690e Binary files /dev/null and b/User-Query-Portal-Superstore/Jobs.xlsx differ diff --git a/User-Query-Portal-Superstore/README.md b/User-Query-Portal-Superstore/README.md new file mode 100644 index 0000000..3c64859 --- /dev/null +++ b/User-Query-Portal-Superstore/README.md @@ -0,0 +1,5 @@ +Python application that simulates interaction with a database, processes user queries, and +returns relevant data. + +#### Link to the web app : +https://user-query-app-superstore-y8vraqdk2rbuepindrdkv8.streamlit.app/ diff --git a/User-Query-Portal-Superstore/User_Query_Application.py b/User-Query-Portal-Superstore/User_Query_Application.py new file mode 100644 index 0000000..d8c7ac7 --- /dev/null +++ b/User-Query-Portal-Superstore/User_Query_Application.py @@ -0,0 +1,130 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Feb 29 22:38:35 2024 + +@author: D VAMIDHAR (dvamsidhar2002@gmail.com) +""" + +# Importing necessary libraries + + +import pandas as pd +import difflib +from sklearn.feature_extraction.text import TfidfVectorizer +from sklearn.metrics.pairwise import cosine_similarity +from nltk.tokenize import RegexpTokenizer +import streamlit as st + +def intent_recognition(query): + data = pd.read_excel('Jobs.xlsx') + + tokenizer = RegexpTokenizer(r'\w+') + data['Query of the Customer'] = data['Query of the Customer'].apply(lambda x: ' '.join(tokenizer.tokenize(x))) + + combine_feat = data['Query of the Customer'] + ' ' + data['Query Type'] + ' ' + data['Who Can Help'] + + # to vectorize the features + + vectorizer = TfidfVectorizer() + feature_vectors = vectorizer.fit_transform(combine_feat) + + # similarity scores + similarity = cosine_similarity(feature_vectors) + + + + list_of_all_queries =data['Query of the Customer'].tolist() + find_close_match = list() + find_close_match = difflib.get_close_matches(query, list_of_all_queries) + + close_match = find_close_match[0] + + index_of_the_query = data[data['Query of the Customer'] == close_match]['index'].values[0] + + similarity_score = list(enumerate(similarity[index_of_the_query])) + + sorted_similarity_score = sorted(similarity_score, key = lambda x:x[1], reverse = True) + + query_of_the_user = list() + + for query1 in sorted_similarity_score: + index = query1[0] + query_of_the_user.append(data[data.index==index]['Query Type'].values[0]) + + + print('Your query is related to : ') + # Set to store unique elements encountered so far + query_type = set() + i = 0 + # Iterate over the list and print only those elements that are not in the set + for word in query_of_the_user: + if word not in query_type: + print(word) + query_type.add(word) + i+=1 + + if i>=3: + break + + import json + + def find_details(query_1): + + # Load the JSON data from the file + with open("Employee Details.json", "r") as f: + data = json.load(f) + + # Find employees with matching support + matching_details = [] + for details in data: + if query_1.lower() in details["Support "].lower(): + matching_details.append(details) + + return matching_details + + query_1 = query_of_the_user[0] + matching_details = find_details(query_1) + + def format_employee_info(employee): + info_string = (f"Query related to : {query_type}\n\n" + f"\nPLEASE CONTACT THE FOLLOWING PERSON FOR SOLUTION : \n" + f"\nEmployee Name: {employee['Name ']}\n" + f"\nDepartment: {employee['Department ']}\n" + f"\nSupport: {employee['Support ']}\n" + f"\nPhone Number: {employee['Phone Number ']}\n" + f"\nEmail: {employee['Email Id ']}\n" + + "-" * 20 + "\n") + return info_string + + query_1 = query_of_the_user[0] + matching_details = find_details(query_1) + + print("USER's Query : ") + print(query) + print("Query related to : ", query_of_the_user[0]) + print("="*50) + print("Please contact the following person(s) for help : ") + print("="*50) + if matching_details: + # Print employee information + for employee in matching_details: + employee_info_string = format_employee_info(employee) + return employee_info_string + else: + return "No matching employees found." + + +def main(): + st.title('User Interaction Portal') + #user input + query = st.text_input('Enter your query : ') + + if st.button('Post Query'): + response = intent_recognition(query) + + st.success(response) + + +if __name__ == "__main__": + main() + diff --git a/User-Query-Portal-Superstore/requirements.txt b/User-Query-Portal-Superstore/requirements.txt new file mode 100644 index 0000000..33f85f6 --- /dev/null +++ b/User-Query-Portal-Superstore/requirements.txt @@ -0,0 +1,7 @@ +numpy +pickle-mixin +streamlit +scikit-learn +nltk +pandas +openpyxl