File size: 916 Bytes
78f11a0
 
 
 
 
 
 
1e18cca
78f11a0
 
 
 
 
 
 
 
 
 
d5f49ca
78f11a0
 
 
930aaf0
78f11a0
 
 
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
import gradio as gr

# Even though it is not imported, it is actually required, it downloads some stuff.
import allennlp_models  # noqa: F401
from allennlp.predictors.predictor import Predictor

# The integration with AllenNLP uses a hf prefix.
predictor = Predictor.from_path("hf://lysandre/bidaf-elmo-model-2020.03.19")

def predict(context, question):
  allenlp_input = {"passage": context, "question": question}
  predictions = predictor.predict_json(allenlp_input)
  return predictions["best_span_str"]
  
title = "Interactive demo: AllenNLP Bidaf Elmo"
description = "Demo for AllenNLP Question Answering model."

iface = gr.Interface(fn=predict, 
  inputs=[gr.inputs.Textbox(label="context"), gr.inputs.Textbox(label="question")],
  outputs='text',
  title=title,
  description=description,
  examples=[["My name is Omar and I live in Mexico", "Where does Omar live?"]],
  enable_queue=True)

iface.launch()