ShaohanTian commited on
Commit
2423a57
·
1 Parent(s): ea84696
Files changed (2) hide show
  1. app.py +21 -26
  2. config.json +5 -0
app.py CHANGED
@@ -1,35 +1,30 @@
1
  import gradio as gr
 
2
 
3
- title = "BERT"
 
4
 
5
- description = "Gradio Demo for BERT. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
 
 
 
6
 
7
- article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1810.04805' target='_blank'>BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding</a></p>"
 
 
 
 
 
 
8
 
 
9
  examples = [
10
- ['Paris is the [MASK] of France.', 'bert-base-cased']
 
11
  ]
12
 
13
- io1 = gr.Interface.load("huggingface/bert-base-cased")
14
- io2 = gr.Interface.load("huggingface/bert-base-uncased")
15
 
16
- def inference(inputtext, model):
17
- if model == "bert-base-cased":
18
- outlabel = io1(inputtext)
19
- else:
20
- outlabel = io2(inputtext)
21
- return outlabel
22
-
23
- inputs = gr.Textbox(label="Context", lines=10)
24
- model_choice = gr.Dropdown(choices=["bert-base-cased", "bert-base-uncased"], label="Model")
25
- outputs = gr.Textbox(label="Output")
26
-
27
- gr.Interface(
28
- fn=inference,
29
- inputs=[inputs, model_choice],
30
- outputs=outputs,
31
- examples=examples,
32
- article=article,
33
- title=title,
34
- description=description
35
- ).launch(enable_queue=True)
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Load the SteelBERT model for mask filling
5
+ fill_mask = pipeline("fill-mask", model="MGE-LLMs/SteelBERT")
6
 
7
+ # Define the Gradio interface
8
+ def mask_filler(text):
9
+ result = fill_mask(text)
10
+ return result[0]["sequence"]
11
 
12
+ iface = gr.Interface(
13
+ fn=mask_filler,
14
+ inputs=gr.Textbox(lines=3, label="Enter a sentence with [MASK] token"),
15
+ outputs=gr.Textbox(label="Completed sentence"),
16
+ title="SteelBERT Mask Filler",
17
+ description="Fill in the masked token using SteelBERT.",
18
+ )
19
 
20
+ # Add some example inputs for the interface
21
  examples = [
22
+ ["SteelBERT is a [MASK] model for filling in missing information."],
23
+ ["I have a [MASK] of apples and oranges."],
24
  ]
25
 
26
+ iface.examples = examples
 
27
 
28
+ # Launch the interface
29
+ if __name__ == "__main__":
30
+ iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "environments": ["python"],
3
+ "command": "python app.py"
4
+ }
5
+