File size: 1,265 Bytes
b69d18c
2147fd0
b69d18c
2147fd0
 
d209cfd
 
 
 
 
2147fd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d209cfd
 
2147fd0
 
 
 
 
d209cfd
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import gradio as gr
from transformers import pipeline, AutoTokenizer

##############
# <Greeting>
# def greet(name):
#     return f"Hello {name}!"

# demo = gr.Interface(fn=greet, inputs="text", outputs="text")


##############
# <Hotdog Not Hotdog>
# pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")

# def predict(image):
#     predictions = pipeline(image)
#     return {p["label"]: p["score"] for p in predictions}

# demo = gr.Interface(
#     predict,
#     inputs=gr.inputs.Image(label="Upload hot dog candidate", type="filepath"),
#     outputs=gr.outputs.Label(num_top_classes=2),
#     title="Hot Dog? Or Not?"
# )

tokenizer = AutoTokenizer.from_pretrained("alabnii/jmedroberta-base-manbyo-wordpiece", **{
    "mecab_kwargs": {
        "mecab_option": "-u MANBYO_201907_Dic-utf8.dic"
    }
})

pipeline = pipeline(
    "fill-mask",
    model="alabnii/jmedroberta-base-manbyo-wordpiece",
    tokenizer=tokenizer,
    top_k=20
)

def fill(text):
    filled = pipeline(text)
    return {x["token_str"]: x["score"] for x in filled}

demo = gr.Interface(
    fill,
    inputs="text",
    outputs=gr.Label(label="Output"),
    title="fill-mask",
    examples=[['この患者は[MASK]と診断された。']]
)
demo.launch()