Jayavathsan commited on
Commit
b4402a4
·
1 Parent(s): 24d7c6d

Upload 3 files

Browse files
pages/Create_ML_Model.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from pages.admin_utils import *
3
+ from sklearn.svm import SVC
4
+ from sklearn.pipeline import make_pipeline
5
+ from sklearn.preprocessing import StandardScaler
6
+ import joblib
7
+
8
+ from pages.admin_utils import *
9
+
10
+
11
+ if 'cleaned_data' not in st.session_state:
12
+ st.session_state['cleaned_data'] =''
13
+ if 'sentences_train' not in st.session_state:
14
+ st.session_state['sentences_train'] =''
15
+ if 'sentences_test' not in st.session_state:
16
+ st.session_state['sentences_test'] =''
17
+ if 'labels_train' not in st.session_state:
18
+ st.session_state['labels_train'] =''
19
+ if 'labels_test' not in st.session_state:
20
+ st.session_state['labels_test'] =''
21
+ if 'svm_classifier' not in st.session_state:
22
+ st.session_state['svm_classifier'] =''
23
+
24
+
25
+ st.title("Let's build our Model...")
26
+
27
+ # Create tabs
28
+ tab_titles = ['Data Preprocessing', 'Model Training', 'Model Evaluation',"Save Model"]
29
+ tabs = st.tabs(tab_titles)
30
+
31
+ # Adding content to each tab
32
+
33
+ #Data Preprocessing TAB
34
+ with tabs[0]:
35
+ st.header('Data Preprocessing')
36
+ st.write('Here we preprocess the data...')
37
+
38
+ # Capture the CSV file
39
+ data = st.file_uploader("Upload CSV file",type="csv")
40
+
41
+ button = st.button("Load data",key="data")
42
+
43
+ if button:
44
+ with st.spinner('Wait for it...'):
45
+ our_data=read_data(data)
46
+ embeddings=get_embeddings()
47
+ st.session_state['cleaned_data'] = create_embeddings(our_data,embeddings)
48
+ st.success('Done!')
49
+
50
+
51
+ #Model Training TAB
52
+ with tabs[1]:
53
+ st.header('Model Training')
54
+ st.write('Here we train the model...')
55
+ button = st.button("Train model",key="model")
56
+
57
+ if button:
58
+ with st.spinner('Wait for it...'):
59
+ st.session_state['sentences_train'], st.session_state['sentences_test'], st.session_state['labels_train'], st.session_state['labels_test']=split_train_test__data(st.session_state['cleaned_data'])
60
+
61
+ # Initialize a support vector machine, with class_weight='balanced' because
62
+ # our training set has roughly an equal amount of positive and negative
63
+ # sentiment sentences
64
+ st.session_state['svm_classifier'] = make_pipeline(StandardScaler(), SVC(class_weight='balanced'))
65
+
66
+ # fit the support vector machine
67
+ st.session_state['svm_classifier'].fit(st.session_state['sentences_train'], st.session_state['labels_train'])
68
+ st.success('Done!')
69
+
70
+ #Model Evaluation TAB
71
+ with tabs[2]:
72
+ st.header('Model Evaluation')
73
+ st.write('Here we evaluate the model...')
74
+ button = st.button("Evaluate model",key="Evaluation")
75
+
76
+ if button:
77
+ with st.spinner('Wait for it...'):
78
+ accuracy_score=get_score(st.session_state['svm_classifier'],st.session_state['sentences_test'],st.session_state['labels_test'])
79
+ st.success(f"Validation accuracy is {100*accuracy_score}%!")
80
+
81
+
82
+ st.write("A sample run:")
83
+
84
+
85
+ #text="lack of communication regarding policy updates salary, can we please look into it?"
86
+ text="Rude driver with scary driving"
87
+ st.write("***Our issue*** : "+text)
88
+
89
+ #Converting out TEXT to NUMERICAL representaion
90
+ embeddings= get_embeddings()
91
+ query_result = embeddings.embed_query(text)
92
+
93
+ #Sample prediction using our trained model
94
+ result= st.session_state['svm_classifier'].predict([query_result])
95
+ st.write("***Department it belongs to*** : "+result[0])
96
+
97
+
98
+ st.success('Done!')
99
+
100
+ #Save model TAB
101
+ with tabs[3]:
102
+ st.header('Save model')
103
+ st.write('Here we save the model...')
104
+
105
+ button = st.button("Save model",key="save")
106
+ if button:
107
+
108
+ with st.spinner('Wait for it...'):
109
+ joblib.dump(st.session_state['svm_classifier'], 'modelsvm.pk1')
110
+ st.success('Done!')
pages/Load_Data_Store.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from dotenv import load_dotenv
3
+ from pages.admin_utils import *
4
+
5
+
6
+ def main():
7
+ load_dotenv()
8
+ st.set_page_config(page_title="Dump PDF to Pinecone - Vector Store")
9
+ st.title("Please upload your files...📁 ")
10
+
11
+ # Upload the pdf file
12
+ pdf = st.file_uploader("Only PDF files allowed", type=["pdf"])
13
+
14
+ # Extract the whole text from the uploaded pdf file
15
+ if pdf is not None:
16
+ with st.spinner('Wait for it...'):
17
+ text=read_pdf_data(pdf)
18
+ st.write("👉Reading PDF done")
19
+
20
+ # Create chunks
21
+ docs_chunks=split_data(text)
22
+ #st.write(docs_chunks)
23
+ st.write("👉Splitting data into chunks done")
24
+
25
+ # Create the embeddings
26
+ embeddings=create_embeddings_load_data()
27
+ st.write("👉Creating embeddings instance done")
28
+
29
+ # Build the vector store (Push the PDF data embeddings)
30
+ push_to_pinecone("e697b71c-d5ed-4c66-8625-ac1c403a2df1","us-west1-gcp-free","tickets",embeddings,docs_chunks)
31
+
32
+ st.success("Successfully pushed the embeddings to Pinecone")
33
+
34
+
35
+ if __name__ == '__main__':
36
+ main()
pages/Pending_tickets.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.title('Departments')
4
+
5
+ # Create tabs
6
+ tab_titles = ['HR Support', 'IT Support', 'Transportation Support']
7
+ tabs = st.tabs(tab_titles)
8
+
9
+ # Add content to each tab
10
+ with tabs[0]:
11
+ st.header('HR Support tickets')
12
+ for ticket in st.session_state['HR_tickets']:
13
+ st.write(str(st.session_state['HR_tickets'].index(ticket)+1)+" : "+ticket)
14
+
15
+
16
+ with tabs[1]:
17
+ st.header('IT Support tickets')
18
+ for ticket in st.session_state['IT_tickets']:
19
+ st.write(str(st.session_state['IT_tickets'].index(ticket)+1)+" : "+ticket)
20
+
21
+ with tabs[2]:
22
+ st.header('Transportation Support tickets')
23
+ for ticket in st.session_state['Transport_tickets']:
24
+ st.write(str(st.session_state['Transport_tickets'].index(ticket)+1)+" : "+ticket)
25
+
26
+