Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,82 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
unmasker = pipeline('fill-mask', model='roberta-base') #bert-base-multilingual-cased') #bert-base-uncased')
|
5 |
+
|
6 |
+
def fill_mask(text):
|
7 |
+
unmasked = unmasker(text)
|
8 |
+
output = {}
|
9 |
+
for unmask in unmasked:
|
10 |
+
output[unmask["token_str"]] = unmask["score"]
|
11 |
+
return output
|
12 |
+
|
13 |
+
examples = [["Hello I'm a [MASK] model."], ["[MASK] is my favourite sports."]]
|
14 |
+
|
15 |
+
css = """
|
16 |
+
footer {display:none !important}
|
17 |
+
.output-markdown{display:none !important}
|
18 |
+
.gr-button-primary {
|
19 |
+
z-index: 14;
|
20 |
+
height: 43px;
|
21 |
+
width: 130px;
|
22 |
+
left: 0px;
|
23 |
+
top: 0px;
|
24 |
+
padding: 0px;
|
25 |
+
cursor: pointer !important;
|
26 |
+
background: none rgb(17, 20, 45) !important;
|
27 |
+
border: none !important;
|
28 |
+
text-align: center !important;
|
29 |
+
font-family: Poppins !important;
|
30 |
+
font-size: 14px !important;
|
31 |
+
font-weight: 500 !important;
|
32 |
+
color: rgb(255, 255, 255) !important;
|
33 |
+
line-height: 1 !important;
|
34 |
+
border-radius: 12px !important;
|
35 |
+
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
|
36 |
+
box-shadow: none !important;
|
37 |
+
}
|
38 |
+
.gr-button-primary:hover{
|
39 |
+
z-index: 14;
|
40 |
+
height: 43px;
|
41 |
+
width: 130px;
|
42 |
+
left: 0px;
|
43 |
+
top: 0px;
|
44 |
+
padding: 0px;
|
45 |
+
cursor: pointer !important;
|
46 |
+
background: none rgb(37, 56, 133) !important;
|
47 |
+
border: none !important;
|
48 |
+
text-align: center !important;
|
49 |
+
font-family: Poppins !important;
|
50 |
+
font-size: 14px !important;
|
51 |
+
font-weight: 500 !important;
|
52 |
+
color: rgb(255, 255, 255) !important;
|
53 |
+
line-height: 1 !important;
|
54 |
+
border-radius: 12px !important;
|
55 |
+
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
|
56 |
+
box-shadow: rgb(0 0 0 / 23%) 0px 1px 7px 0px !important;
|
57 |
+
}
|
58 |
+
.hover\:bg-orange-50:hover {
|
59 |
+
--tw-bg-opacity: 1 !important;
|
60 |
+
background-color: rgb(229,225,255) !important;
|
61 |
+
}
|
62 |
+
.to-orange-200 {
|
63 |
+
--tw-gradient-to: rgb(37 56 133 / 37%) !important;
|
64 |
+
}
|
65 |
+
.from-orange-400 {
|
66 |
+
--tw-gradient-from: rgb(17, 20, 45) !important;
|
67 |
+
--tw-gradient-to: rgb(255 150 51 / 0);
|
68 |
+
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
|
69 |
+
}
|
70 |
+
.group-hover\:from-orange-500{
|
71 |
+
--tw-gradient-from:rgb(17, 20, 45) !important;
|
72 |
+
--tw-gradient-to: rgb(37 56 133 / 37%);
|
73 |
+
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;
|
74 |
+
}
|
75 |
+
.group:hover .group-hover\:text-orange-500{
|
76 |
+
--tw-text-opacity: 1 !important;
|
77 |
+
color:rgb(37 56 133 / var(--tw-text-opacity)) !important;
|
78 |
+
}
|
79 |
+
"""
|
80 |
+
|
81 |
+
demo = gr.Interface(fn=fill_mask, inputs=gr.Textbox(lines=1, label="Input"), outputs=gr.Label(label="Output"),title="Fill Mask | Data Science Dojo", theme="light", examples=examples, css=css)
|
82 |
+
demo.launch()
|