from pprint import pformat import spacy import gradio as gr from textacy import preprocessing import en_ethicalads_topics ea_nlp = en_ethicalads_topics.load() preprocessor = preprocessing.make_pipeline( preprocessing.normalize.unicode, preprocessing.remove.punctuation, preprocessing.normalize.whitespace, ) def classify(input_text): processed_input = preprocessor(input_text) ea_output = ea_nlp(processed_input) return pformat(sorted(ea_output.cats.items(), key=lambda x: x[1], reverse=True)) iface = gr.Interface( fn=classify, inputs=gr.Textbox(lines=5, placeholder="Input text to detect the topic classification. Works best on inputs of 100+ words."), outputs="text", ) iface.launch()