ShaohanTian commited on
Commit
8682d4e
·
1 Parent(s): cdc45b2
Files changed (1) hide show
  1. app.py +32 -6
app.py CHANGED
@@ -1,9 +1,35 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox")
7
-
8
- if __name__ == "__main__":
9
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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", default="bert-base-cased")
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)