Delete appStore/classifier.py
Browse files- appStore/classifier.py +0 -116
appStore/classifier.py
DELETED
@@ -1,116 +0,0 @@
|
|
1 |
-
# set path
|
2 |
-
import glob, os, sys;
|
3 |
-
sys.path.append('../utils')
|
4 |
-
from setfit import SetFitModel
|
5 |
-
#import needed libraries
|
6 |
-
#import seaborn as sns
|
7 |
-
#import matplotlib.pyplot as plt
|
8 |
-
#import numpy as np
|
9 |
-
#import pandas as pd
|
10 |
-
#import streamlit as st
|
11 |
-
from utils.groups_classifier import load_groupsClassifier, groups_classification
|
12 |
-
#import logging
|
13 |
-
#logger = logging.getLogger(__name__)
|
14 |
-
from utils.config import get_classifier_params
|
15 |
-
#from utils.preprocessing import paraLengthCheck
|
16 |
-
#from io import BytesIO
|
17 |
-
#import xlsxwriter
|
18 |
-
#import plotly.express as px
|
19 |
-
|
20 |
-
vg_model = SetFitModel.from_pretrained("leavoigt/vulnerable_groups")
|
21 |
-
|
22 |
-
|
23 |
-
# Retrieve the necessary paramaters
|
24 |
-
classifier_identifier = 'group_classification'
|
25 |
-
params = get_classifier_params(classifier_identifier)
|
26 |
-
|
27 |
-
def app():
|
28 |
-
|
29 |
-
### Main app code ###
|
30 |
-
with st.container():
|
31 |
-
|
32 |
-
# Classify groups
|
33 |
-
df = group_classification(haystack_doc=df, threshold= params['threshold'])
|
34 |
-
|
35 |
-
def groups_display():
|
36 |
-
# if 'key1' in st.session_state:
|
37 |
-
# df = st.session_state.key1
|
38 |
-
|
39 |
-
|
40 |
-
# df['Action_check'] = df['Policy-Action Label'].apply(lambda x: True if 'Action' in x else False)
|
41 |
-
# hits = df[df['Action_check'] == True]
|
42 |
-
# # hits['GHG Label'] = hits['GHG Label'].apply(lambda i: _lab_dict[i])
|
43 |
-
# range_val = min(5,len(hits))
|
44 |
-
# if range_val !=0:
|
45 |
-
# count_action = len(hits)
|
46 |
-
|
47 |
-
# st.write("")
|
48 |
-
# st.markdown("###### Top few Action Classified paragraph/text results from list of {} classified paragraphs ######".format(count_action))
|
49 |
-
# st.markdown("""<hr style="height:10px;border:none;color:#097969;background-color:#097969;" /> """, unsafe_allow_html=True)
|
50 |
-
# range_val = min(5,len(hits))
|
51 |
-
# for i in range(range_val):
|
52 |
-
# # the page number reflects the page that contains the main paragraph
|
53 |
-
# # according to split limit, the overlapping part can be on a separate page
|
54 |
-
# st.write('**Result {}** : `page {}`, `Sector: {}`,\
|
55 |
-
# `Indicators: {}`, `Adapt-Mitig :{}`'\
|
56 |
-
# .format(i+1,
|
57 |
-
# hits.iloc[i]['page'], hits.iloc[i]['Sector Label'],
|
58 |
-
# hits.iloc[i]['Indicator Label'],hits.iloc[i]['Adapt-Mitig Label']))
|
59 |
-
# st.write("\t Text: \t{}".format(hits.iloc[i]['text'].replace("\n", " ")))
|
60 |
-
# hits = hits.reset_index(drop =True)
|
61 |
-
# st.write('----------------')
|
62 |
-
# st.write('Explore the data')
|
63 |
-
# st.write(hits)
|
64 |
-
# df.drop(columns = ['Action_check'],inplace=True)
|
65 |
-
# df_xlsx = to_excel(df)
|
66 |
-
|
67 |
-
# with st.sidebar:
|
68 |
-
# st.write('-------------')
|
69 |
-
# st.download_button(label='📥 Download Result',
|
70 |
-
# data=df_xlsx ,
|
71 |
-
# file_name= 'cpu_analysis.xlsx')
|
72 |
-
|
73 |
-
# else:
|
74 |
-
# st.info("🤔 No Actions found")
|
75 |
-
|
76 |
-
|
77 |
-
# def groups_display():
|
78 |
-
# if 'key1' in st.session_state:
|
79 |
-
# df = st.session_state.key1
|
80 |
-
|
81 |
-
|
82 |
-
# df['Policy_check'] = df['Policy-Action Label'].apply(lambda x: True if 'Policies & Plans' in x else False)
|
83 |
-
# hits = df[df['Policy_check'] == True]
|
84 |
-
# # hits['GHG Label'] = hits['GHG Label'].apply(lambda i: _lab_dict[i])
|
85 |
-
# range_val = min(5,len(hits))
|
86 |
-
# if range_val !=0:
|
87 |
-
# count_policy = len(hits)
|
88 |
-
|
89 |
-
# st.write("")
|
90 |
-
# st.markdown("###### Top few Policy/Plans Classified paragraph/text results from list of {} classified paragraphs ######".format(count_policy))
|
91 |
-
# st.markdown("""<hr style="height:10px;border:none;color:#097969;background-color:#097969;" /> """, unsafe_allow_html=True)
|
92 |
-
# range_val = min(5,len(hits))
|
93 |
-
# for i in range(range_val):
|
94 |
-
# # the page number reflects the page that contains the main paragraph
|
95 |
-
# # according to split limit, the overlapping part can be on a separate page
|
96 |
-
# st.write('**Result {}** : `page {}`, `Sector: {}`,\
|
97 |
-
# `Indicators: {}`, `Adapt-Mitig :{}`'\
|
98 |
-
# .format(i+1,
|
99 |
-
# hits.iloc[i]['page'], hits.iloc[i]['Sector Label'],
|
100 |
-
# hits.iloc[i]['Indicator Label'],hits.iloc[i]['Adapt-Mitig Label']))
|
101 |
-
# st.write("\t Text: \t{}".format(hits.iloc[i]['text'].replace("\n", " ")))
|
102 |
-
# hits = hits.reset_index(drop =True)
|
103 |
-
# st.write('----------------')
|
104 |
-
# st.write('Explore the data')
|
105 |
-
# st.write(hits)
|
106 |
-
# df.drop(columns = ['Policy_check'],inplace=True)
|
107 |
-
# df_xlsx = to_excel(df)
|
108 |
-
|
109 |
-
# with st.sidebar:
|
110 |
-
# st.write('-------------')
|
111 |
-
# st.download_button(label='📥 Download Result',
|
112 |
-
# data=df_xlsx ,
|
113 |
-
# file_name= 'vulnerable_groups.xlsx')
|
114 |
-
|
115 |
-
# else:
|
116 |
-
# st.info("🤔 No Groups found")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|