Spaces:
Running
Running
David Fischer
commited on
Commit
•
2589f84
1
Parent(s):
95e849c
Add our model and interface
Browse files- app.py +28 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spacy
|
2 |
+
import gradio as gr
|
3 |
+
from textacy import preprocessing
|
4 |
+
|
5 |
+
import en_ethicalads_topics
|
6 |
+
|
7 |
+
|
8 |
+
ea_nlp = en_ethicalads_topics.load()
|
9 |
+
|
10 |
+
preprocessor = preprocessing.make_pipeline(
|
11 |
+
preprocessing.normalize.unicode,
|
12 |
+
preprocessing.remove.punctuation,
|
13 |
+
preprocessing.normalize.whitespace,
|
14 |
+
)
|
15 |
+
|
16 |
+
|
17 |
+
def classify(input_text):
|
18 |
+
processed_input = preprocessor(input_text)
|
19 |
+
ea_output = ea_nlp(processed_input)
|
20 |
+
return str(sorted(ea_output.cats.items(), key=lambda x: x[1], reverse=True))
|
21 |
+
|
22 |
+
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=classify,
|
25 |
+
inputs=gr.Textbox(lines=5, placeholder="Input text to detect the topic classification..."),
|
26 |
+
outputs="text",
|
27 |
+
)
|
28 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
spacy
|
2 |
+
textacy
|
3 |
+
gradio
|
4 |
+
|
5 |
+
https://huggingface.co/davidfischer/en_ethicalads_topics
|