bidaf-elmo / app.py
osanseviero's picture
osanseviero HF staff
Update app.py
ca65ffe
raw
history blame contribute delete
No virus
916 Bytes
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()