Spaces:
Sleeping
Sleeping
Commit
•
de06228
1
Parent(s):
e5a2fe5
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
2 |
import gradio as grad
|
3 |
import ast
|
@@ -14,3 +39,5 @@ def answer_question(question, context):
|
|
14 |
return response
|
15 |
|
16 |
grad.Interface(answer_question, inputs=["text", "text"], outputs="text").launch()
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
|
2 |
+
import torch
|
3 |
+
import gradio as grad
|
4 |
+
import ast
|
5 |
+
|
6 |
+
_pretrainedModelName = "savasy/bert-base-turkish-squad"
|
7 |
+
_tokenizer = AutoTokenizer.from_pretrained(_pretrainedModelName)
|
8 |
+
_model = AutoModelForQuestionAnswering.from_pretrained(_pretrainedModelName)
|
9 |
+
_pipeline = pipeline("question-answering", model = _model, tokenizer = _tokenizer)
|
10 |
+
|
11 |
+
|
12 |
+
def answer_question(question, answer):
|
13 |
+
text = "{" + "'question': '"+question+"', 'context':'"+context+"'}"
|
14 |
+
di = ast.literal_eval(text)
|
15 |
+
response = _pipeline(di)
|
16 |
+
return response.get("answer")
|
17 |
+
|
18 |
+
|
19 |
+
grad.Interface(answer_question, inputs=["text", "text"], outputs=["text"]).launch()
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
'''
|
26 |
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
27 |
import gradio as grad
|
28 |
import ast
|
|
|
39 |
return response
|
40 |
|
41 |
grad.Interface(answer_question, inputs=["text", "text"], outputs="text").launch()
|
42 |
+
'''
|
43 |
+
|