Spaces:
Build error
Build error
Commit
·
78f11a0
1
Parent(s):
a40c2ea
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
# Even though it is not imported, it is actually required, it downloads some stuff.
|
4 |
+
import allennlp_models # noqa: F401
|
5 |
+
from allennlp.predictors.predictor import Predictor
|
6 |
+
|
7 |
+
# The integration with AllenNLP uses a hf prefix.
|
8 |
+
predictor = Predictor.from_path("hf://lysandre/bidaf-elmo-model-2020.03.19)
|
9 |
+
|
10 |
+
def predict(context, question):
|
11 |
+
allenlp_input = {"passage": context, "question": question}
|
12 |
+
predictions = predictor.predict_json(allenlp_input)
|
13 |
+
return predictions["best_span_str"]
|
14 |
+
|
15 |
+
title = "Interactive demo: AllenNLP Bidaf Elmo"
|
16 |
+
description = "Demo for AllenNLP Question Answering model."
|
17 |
+
|
18 |
+
iface = gr.Interface(fn=predict,
|
19 |
+
inputs=[gr.inputs.TextBox(label="context"), gr.inputs.TextBox(label="question")],
|
20 |
+
outputs='text',
|
21 |
+
title=title,
|
22 |
+
description=description,
|
23 |
+
enable_queue=True)
|
24 |
+
|
25 |
+
iface.launch()
|