Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,23 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
def question_answer(context, question):
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
gr.Interface(fn=question_answer, inputs=["text", "text"], outputs=["
|
|
|
1 |
import gradio as gr
|
2 |
+
from simpletransformers.question_answering import QuestionAnsweringModel, QuestionAnsweringArgs
|
3 |
+
import constants
|
4 |
+
|
5 |
+
model = QuestionAnsweringModel(
|
6 |
+
constants.MODEL_TYPE, constants.MODEL_NAME, use_cuda=constants.USE_CUDA
|
7 |
+
)
|
8 |
def question_answer(context, question):
|
9 |
+
to_predict = [
|
10 |
+
{
|
11 |
+
"context": context,
|
12 |
+
"qas": [
|
13 |
+
{
|
14 |
+
"question": question,
|
15 |
+
"id": "0",
|
16 |
+
}
|
17 |
+
],
|
18 |
+
}
|
19 |
+
]
|
20 |
+
answers, probabilities = model.predict(to_predict)
|
21 |
+
return answers[0]['answer'][0]
|
22 |
|
23 |
+
gr.Interface(fn=question_answer, inputs=["text", "text"], outputs=["text"]).launch()
|