import gradio import re from preprocess_function import lam_list from kbert_topics import extract_topics from mapping import get_mapping from topics_extraction import classify from PyDictionary import PyDictionary dictionary=PyDictionary() from nltk.stem import PorterStemmer stemmer = PorterStemmer() def get_output(event_info): if len(event_info.split(' '))>=20: # print(get_mapping(event_info)) topic_name, distance_name,topic_name_dep, distance_name_dep,tags_list = get_mapping(event_info) if distance_name!=None: sectors_main = topic_name + [topic_name_dep] sectors = [re.split(r'[ _]', x) for x in sectors_main] flattened_list = [item for sublist in sectors for item in (sublist if isinstance(sublist, list) else [sublist])] flattened_list.extend([x.strip().replace(' ','_') for x in sectors_main]) flattened_list = [ x.strip() for x in flattened_list if x!=''] flattened_list_v,flattened_list_n = lam_list(flattened_list) flattened_list = flattened_list_v + flattened_list_n tags_list_check_v,tags_list_check_n = lam_list(tags_list) tag_dict_v = dict(zip(tags_list_check_v, tags_list)) others_v = {check:tag for (check, tag) in tag_dict_v.items() if check not in flattened_list} tag_dict_n = dict(zip(tags_list_check_n, tags_list)) others_n = {check:tag for (check, tag) in tag_dict_n.items() if check not in flattened_list} others = list(others_v.keys()) + list(others_n.keys()) others = list(set(others)) list1_stemmed = {stemmer.stem(word) for word in list(set(flattened_list))} final_list_stemmed = [(word, stemmer.stem(word)) for word in others] others = [word for word, stemmed in final_list_stemmed if stemmed not in list1_stemmed] else: others = [] work_list, keywords_2 = extract_topics(event_info) work_list = [i for i in work_list if bool(dictionary.meaning(i))] return str(topic_name) + ' '+str(distance_name), str(topic_name_dep) + ' '+str(distance_name_dep),str(tags_list), str(work_list), str(others) else: return 'Event discription should have >= 20 words', None, None, None,None with gradio.Blocks(theme = 'gradio/monochrome', title = 'Keyword clustering Demo') as keyword_cluster_demo: gradio.Markdown( "
Interface for checking results of keyword generation and sector/other industries mapping
" ) gradio.HTML( """