Spaces:
Build error
Build error
danseith
commited on
Commit
·
3566540
1
Parent(s):
9f0fca6
Added back in demo definition
Browse files
app.py
CHANGED
|
@@ -6,6 +6,13 @@ unmasker = pipeline("fill-mask", model="anferico/bert-for-patents")
|
|
| 6 |
|
| 7 |
example = 'A crustless sandwich made from two slices of baked bread'
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# class TempScalePipe(Pipeline):
|
| 10 |
# def _forward(self, model_inputs):
|
| 11 |
# outputs = self.model(**model_inputs)
|
|
@@ -19,26 +26,22 @@ example = 'A crustless sandwich made from two slices of baked bread'
|
|
| 19 |
#
|
| 20 |
|
| 21 |
def unmask(text):
|
| 22 |
-
text = add_mask(text)
|
| 23 |
res = unmasker(text)
|
| 24 |
out = {item["token_str"]: item["score"] for item in res}
|
| 25 |
return out
|
| 26 |
|
| 27 |
|
|
|
|
| 28 |
textbox = gr.Textbox(label="Type language here", lines=5)
|
| 29 |
-
import gradio as gr
|
| 30 |
from transformers import pipeline, Pipeline
|
| 31 |
|
| 32 |
|
| 33 |
# unmasker = pipeline("fill-mask", model="anferico/bert-for-patents")
|
| 34 |
#
|
| 35 |
#
|
| 36 |
-
|
| 37 |
-
# split_text = text.split()
|
| 38 |
-
# idx = np.random.randint(len(split_text), size=size)
|
| 39 |
-
# for i in idx:
|
| 40 |
-
# split_text[i] = '[MASK]'
|
| 41 |
-
# return ' '.join(split_text)
|
| 42 |
#
|
| 43 |
#
|
| 44 |
# def unmask(text):
|
|
@@ -50,22 +53,11 @@ from transformers import pipeline, Pipeline
|
|
| 50 |
#
|
| 51 |
# textbox = gr.Textbox(label="Type language here", lines=5)
|
| 52 |
#
|
| 53 |
-
# demo = gr.Interface(
|
| 54 |
-
# fn=unmask,
|
| 55 |
-
# inputs=textbox,
|
| 56 |
-
# outputs="label",
|
| 57 |
-
# examples=[
|
| 58 |
-
#
|
| 59 |
-
# ],
|
| 60 |
-
# )
|
| 61 |
-
|
| 62 |
-
demo.launch()
|
| 63 |
demo = gr.Interface(
|
| 64 |
fn=unmask,
|
| 65 |
inputs=textbox,
|
| 66 |
outputs="label",
|
| 67 |
-
examples=[
|
| 68 |
-
],
|
| 69 |
)
|
| 70 |
|
| 71 |
-
demo.launch()
|
|
|
|
| 6 |
|
| 7 |
example = 'A crustless sandwich made from two slices of baked bread'
|
| 8 |
|
| 9 |
+
# def add_mask(text, size=1):
|
| 10 |
+
# split_text = text.split()
|
| 11 |
+
# idx = np.random.randint(len(split_text), size=size)
|
| 12 |
+
# for i in idx:
|
| 13 |
+
# split_text[i] = '[MASK]'
|
| 14 |
+
# return ' '.join(split_text)
|
| 15 |
+
|
| 16 |
# class TempScalePipe(Pipeline):
|
| 17 |
# def _forward(self, model_inputs):
|
| 18 |
# outputs = self.model(**model_inputs)
|
|
|
|
| 26 |
#
|
| 27 |
|
| 28 |
def unmask(text):
|
| 29 |
+
# text = add_mask(text)
|
| 30 |
res = unmasker(text)
|
| 31 |
out = {item["token_str"]: item["score"] for item in res}
|
| 32 |
return out
|
| 33 |
|
| 34 |
|
| 35 |
+
|
| 36 |
textbox = gr.Textbox(label="Type language here", lines=5)
|
| 37 |
+
# import gradio as gr
|
| 38 |
from transformers import pipeline, Pipeline
|
| 39 |
|
| 40 |
|
| 41 |
# unmasker = pipeline("fill-mask", model="anferico/bert-for-patents")
|
| 42 |
#
|
| 43 |
#
|
| 44 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
#
|
| 46 |
#
|
| 47 |
# def unmask(text):
|
|
|
|
| 53 |
#
|
| 54 |
# textbox = gr.Textbox(label="Type language here", lines=5)
|
| 55 |
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
demo = gr.Interface(
|
| 57 |
fn=unmask,
|
| 58 |
inputs=textbox,
|
| 59 |
outputs="label",
|
| 60 |
+
examples=[example],
|
|
|
|
| 61 |
)
|
| 62 |
|
| 63 |
+
demo.launch()
|