Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,83 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
classifier = pipeline("zero-shot-classification", model="tasksource/ModernBERT-base-nli")
|
5 |
+
|
6 |
+
def zeroShotClassification(text_input, candidate_labels):
|
7 |
+
labels = [label.strip(' ') for label in candidate_labels.split(',')]
|
8 |
+
output = {}
|
9 |
+
prediction = classifier(text_input, labels)
|
10 |
+
for i in range(len(prediction['labels'])):
|
11 |
+
output[prediction['labels'][i]] = prediction['scores'][i]
|
12 |
+
return output
|
13 |
+
|
14 |
+
examples = [["One day I will see the world", "travel, live, die, future"]]
|
15 |
+
|
16 |
+
css = """
|
17 |
+
footer {display:none !important}
|
18 |
+
.output-markdown{display:none !important}
|
19 |
+
.gr-button-primary {
|
20 |
+
z-index: 14;
|
21 |
+
height: 43px;
|
22 |
+
width: 130px;
|
23 |
+
left: 0px;
|
24 |
+
top: 0px;
|
25 |
+
padding: 0px;
|
26 |
+
cursor: pointer !important;
|
27 |
+
background: none rgb(17, 20, 45) !important;
|
28 |
+
border: none !important;
|
29 |
+
text-align: center !important;
|
30 |
+
font-family: Poppins !important;
|
31 |
+
font-size: 14px !important;
|
32 |
+
font-weight: 500 !important;
|
33 |
+
color: rgb(255, 255, 255) !important;
|
34 |
+
line-height: 1 !important;
|
35 |
+
border-radius: 12px !important;
|
36 |
+
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
|
37 |
+
box-shadow: none !important;
|
38 |
+
}
|
39 |
+
.gr-button-primary:hover{
|
40 |
+
z-index: 14;
|
41 |
+
height: 43px;
|
42 |
+
width: 130px;
|
43 |
+
left: 0px;
|
44 |
+
top: 0px;
|
45 |
+
padding: 0px;
|
46 |
+
cursor: pointer !important;
|
47 |
+
background: none rgb(66, 133, 244) !important;
|
48 |
+
border: none !important;
|
49 |
+
text-align: center !important;
|
50 |
+
font-family: Poppins !important;
|
51 |
+
font-size: 14px !important;
|
52 |
+
font-weight: 500 !important;
|
53 |
+
color: rgb(255, 255, 255) !important;
|
54 |
+
line-height: 1 !important;
|
55 |
+
border-radius: 12px !important;
|
56 |
+
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
|
57 |
+
box-shadow: rgb(0 0 0 / 23%) 0px 1px 7px 0px !important;
|
58 |
+
}
|
59 |
+
.hover\:bg-orange-50:hover {
|
60 |
+
--tw-bg-opacity: 1 !important;
|
61 |
+
background-color: rgb(229,225,255) !important;
|
62 |
+
}
|
63 |
+
.to-orange-200 {
|
64 |
+
--tw-gradient-to: rgb(37 56 133 / 37%) !important;
|
65 |
+
}
|
66 |
+
.from-orange-400 {
|
67 |
+
--tw-gradient-from: rgb(17, 20, 45) !important;
|
68 |
+
--tw-gradient-to: rgb(255 150 51 / 0);
|
69 |
+
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
|
70 |
+
}
|
71 |
+
.group-hover\:from-orange-500{
|
72 |
+
--tw-gradient-from:rgb(17, 20, 45) !important;
|
73 |
+
--tw-gradient-to: rgb(37 56 133 / 37%);
|
74 |
+
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
|
75 |
+
}
|
76 |
+
.group:hover .group-hover\:text-orange-500{
|
77 |
+
--tw-text-opacity: 1 !important;
|
78 |
+
color:rgb(37 56 133 / var(--tw-text-opacity)) !important;
|
79 |
+
}
|
80 |
+
"""
|
81 |
+
|
82 |
+
demo = gr.Interface(fn=zeroShotClassification, inputs=[gr.Textbox(label="Input"), gr.Textbox(label="Candidate Labels")], outputs=gr.Label(label="Classification"), title="Zero Shot Text Classification | Data Science Dojo", examples=examples, css=css)
|
83 |
+
demo.launch()
|