Spaces:
Build error
Build error
Download pages/Classification.py from vmalapaka/GrievanceTicketGeneration_ChatBot: direct link, hf CLI and curl.
- Browser
- Download file 2.65 kB
-
https://huggingface.co/spaces/vmalapaka/GrievanceTicketGeneration_ChatBot/resolve/main/pages/Classification.py
- Command line
-
hf download hf://spaces/vmalapaka/GrievanceTicketGeneration_ChatBot/pages/Classification.py
-
curl -L -o Classification.py https://huggingface.co/spaces/vmalapaka/GrievanceTicketGeneration_ChatBot/resolve/main/pages/Classification.py
2.65 kB
| import streamlit as st | |
| from pages.utils import * | |
| from sklearn.svm import SVC | |
| from sklearn.pipeline import make_pipeline | |
| from sklearn.preprocessing import StandardScaler | |
| import joblib | |
| from utils import * | |
| if 'cleaned_data' not in st.session_state: | |
| st.session_state['cleaned_data'] ='' | |
| if 'sentences_train' not in st.session_state: | |
| st.session_state['sentences_train'] ='' | |
| if 'sentences_test' not in st.session_state: | |
| st.session_state['sentences_test'] ='' | |
| if 'labels_train' not in st.session_state: | |
| st.session_state['labels_train'] ='' | |
| if 'labels_test' not in st.session_state: | |
| st.session_state['labels_test'] ='' | |
| if 'svm_classifier' not in st.session_state: | |
| st.session_state['svm_classifier'] ='' | |
| tab_titles = ['Data Preprocessing', 'Model Training', 'Model Evaluation',"Save Model"] | |
| tabs = st.tabs(tab_titles) | |
| with tabs[0]: | |
| st.header('Data Preprocessing') | |
| # Upload the CSV file | |
| data = st.file_uploader("Upload CSV file",type="csv") | |
| button = st.button("Load data",key="data") | |
| if button: | |
| with st.spinner('Loading...'): | |
| our_data=read_data(data) | |
| embeddings=get_embeddings() | |
| st.session_state['cleaned_data'] = create_embeddings(our_data,embeddings) | |
| st.success('Data Preprocessed') | |
| with tabs[1]: | |
| st.header('Model Training') | |
| button = st.button("Train model",key="model") | |
| if button: | |
| with st.spinner('Loading...'): | |
| 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']) | |
| st.session_state['svm_classifier'] = make_pipeline(StandardScaler(), SVC(class_weight='balanced')) | |
| # fit the support vector machine | |
| st.session_state['svm_classifier'].fit(st.session_state['sentences_train'], st.session_state['labels_train']) | |
| st.success('Model Trained') | |
| with tabs[2]: | |
| st.header('Model Evaluation') | |
| button = st.button("Evaluate model",key="Evaluation") | |
| if button: | |
| with st.spinner('Loading...'): | |
| accuracy_score=get_score(st.session_state['svm_classifier'],st.session_state['sentences_test'],st.session_state['labels_test']) | |
| st.success(f"Validation accuracy is {100*accuracy_score}%!") | |
| with tabs[3]: | |
| st.header('Save classified model') | |
| button = st.button("Save model",key="save") | |
| if button: | |
| with st.spinner('Loading...'): | |
| joblib.dump(st.session_state['svm_classifier'], 'modelsvm.pk1') | |
| st.success('Done!') |