hugging2021 commited on
Commit
15d1762
·
verified ·
1 Parent(s): e3621af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -6,24 +6,24 @@ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1810.048
6
 
7
  examples = [
8
  ['Paris is the [MASK] of France.', 'bert-base-cased']
9
- ['I love [MASK]', 'bert-base-uncased']
10
  ]
11
 
12
  # Lade die Interfaces für die Modelle
13
- io1 = gr.load("huggingface/bert-base-cased")
14
- io2 = gr.load("huggingface/bert-base-uncased")
15
 
16
  def inference(inputtext, model):
17
  if "[MASK]" not in inputtext:
18
- return "Error: The input text must contain the [MASK] token."
19
 
20
  if model == "bert-base-cased":
21
  outlabel = io1(inputtext)
22
  elif model == "bert-base-uncased":
23
  outlabel = io2(inputtext)
24
  else:
25
- outlabel = "Invalid model selected"
26
- return str(outlabel)
 
27
 
28
  # Aktualisierte Gradio-Syntax
29
  gr.Interface(
@@ -32,7 +32,7 @@ gr.Interface(
32
  gr.Textbox(label="Context", lines=10, placeholder="Enter text with [MASK] token"),
33
  gr.Dropdown(choices=["bert-base-cased", "bert-base-uncased"], value="bert-base-cased", label="model")
34
  ],
35
- outputs=gr.Label(label="Output"),
36
  examples=examples,
37
  article=article,
38
  title=title,
 
6
 
7
  examples = [
8
  ['Paris is the [MASK] of France.', 'bert-base-cased']
 
9
  ]
10
 
11
  # Lade die Interfaces für die Modelle
12
+ io1 = gr.Interface.load("huggingface/bert-base-cased")
13
+ io2 = gr.Interface.load("huggingface/bert-base-uncased")
14
 
15
  def inference(inputtext, model):
16
  if "[MASK]" not in inputtext:
17
+ return {"error": "The input text must contain the [MASK] token."}
18
 
19
  if model == "bert-base-cased":
20
  outlabel = io1(inputtext)
21
  elif model == "bert-base-uncased":
22
  outlabel = io2(inputtext)
23
  else:
24
+ return {"error": "Invalid model selected"}
25
+
26
+ return outlabel
27
 
28
  # Aktualisierte Gradio-Syntax
29
  gr.Interface(
 
32
  gr.Textbox(label="Context", lines=10, placeholder="Enter text with [MASK] token"),
33
  gr.Dropdown(choices=["bert-base-cased", "bert-base-uncased"], value="bert-base-cased", label="model")
34
  ],
35
+ outputs=gr.JSON(label="Output"), # We use JSON to display errors or outputs
36
  examples=examples,
37
  article=article,
38
  title=title,