Spaces:
Runtime error
Runtime error
bchoister12321
commited on
Commit
β’
6bf8f89
1
Parent(s):
8deba4c
add zero shot classifier
Browse files- app.py +3 -0
- classifier.py +23 -0
app.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
def greet(name):
|
4 |
return "Hello " + name + "!!"
|
|
|
1 |
import gradio as gr
|
2 |
+
from classifier import classify
|
3 |
+
|
4 |
+
gr.Interface(fn=classify, inputs="text", outputs="text").launch()
|
5 |
|
6 |
def greet(name):
|
7 |
return "Hello " + name + "!!"
|
classifier.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
umbrellaSubjects = [
|
5 |
+
"Science, Technology, Engineering, Mathematics",
|
6 |
+
"Philosophy",
|
7 |
+
"Arts and Humanities",
|
8 |
+
"Social Sciences",
|
9 |
+
"Languages",
|
10 |
+
"Professional Studies"
|
11 |
+
]
|
12 |
+
classifier = pipeline("zero-shot-classification", model="vicgalle/xlm-roberta-large-xnli-anli")
|
13 |
+
|
14 |
+
def process_string(string):
|
15 |
+
# Remove whitespace from string
|
16 |
+
string = string.replace(' ', '')
|
17 |
+
# Split string by comma
|
18 |
+
string_list = string.split(',')
|
19 |
+
# Return list with no whitespace
|
20 |
+
return [term.strip() for term in string_list]
|
21 |
+
def classify(sentences,categories):
|
22 |
+
return classifier(process_string(sentences),process_string(categories))
|
23 |
+
|