#https://www.analyticsvidhya.com/blog/2021/04/create-interface-for-your-machine-learning-models-using-gradio-python-library/ import re import string import pandas as pd import gradio as gr from gensim import models import gensim.corpora as corpora from nltk.corpus import stopwords from gensim.models import LdaModel from gensim.corpora import Dictionary lista_exclusiones = [] with open(r'datos/lista_exclusiones.txt', 'r') as lta: for linea in lta: x = linea[:-1] lista_exclusiones.append(x) df = pd.read_csv('datos/df_general_entrenamiento_v2.csv', index_col= 0) lda_gensim = LdaModel.load('modelo_gensim_v1') diccionario = Dictionary.load_from_text('diccionario') corpus = corpora.MmCorpus('corpus_gensim.mm') lista_estados = [e for e in df.groupby(by= 'Entidad').groups] def remover_palabras_breves(texto): nuevo_texto = re.sub(r'\b[a-zA-Z]{1}\b', '', texto) nuevo_texto = re.sub(r'\b[a-zA-Z]{2}\b', '', nuevo_texto) nuevo_texto = re.sub(r'\b[a-zA-Z]{3}\b', '', nuevo_texto) nuevo_texto = re.sub(r'\s+', ' ', nuevo_texto) return nuevo_texto def remover_exclusiones(texto): return " ".join([palabra for palabra in str(texto).split() if palabra not in lista_exclusiones]) def remover_emojis(cadena): patron_emoji = re.compile("[" u"\U0001F600-\U0001F64F" # emoticones u"\U0001F300-\U0001F5FF" # símbolos y pictogramas u"\U0001F680-\U0001F6FF" # transporte símbolos de mapas u"\U0001F1E0-\U0001F1FF" # banderas (iOS) u"\U00002500-\U00002BEF" # caracteres chinos u"\U00002702-\U000027B0" u"\U00002702-\U000027B0" u"\U000024C2-\U0001F251" u"\U0001f926-\U0001f937" u"\U00010000-\U0010ffff" u"\u2640-\u2642" u"\u2600-\u2B55" u"\u200d" u"\u23cf" u"\u23e9" u"\u231a" u"\ufe0f" # dingbats (¿?) u"\u3030" "]+", flags= re.UNICODE) return patron_emoji.sub(r'', cadena) iface = gr.Interface(fn= mostrar_topicos, inputs= ['text', gr.Dropdown(choices= lista_estados)], outputs= ['text']) iface.launch()