Spaces:
Sleeping
Sleeping
File size: 733 Bytes
03411b5 2589f84 03411b5 2589f84 a839f98 2589f84 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
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()
|