Spaces:
Runtime error
Runtime error
File size: 2,660 Bytes
8259bb2 65ad43e 2dfed0c 65ad43e 4f6c52f 65ad43e 4f6c52f 8259bb2 4f6c52f |
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import gradio as gr
from transformers import pipeline
question_answerer = pipeline("question-answering")
context = r"""
Extractive Question Answering is the task of extracting an answer from a text given a question. An example of a
question answering dataset is the SQuAD dataset, which is entirely based on that task. If you would like to fine-tune
a model on a SQuAD task, you may leverage the examples/pytorch/question-answering/run_squad.py script.
"""
result = question_answerer(question="What is extractive question answering?", context=context)
print(f"Answer: '{result['answer']}', score: {round(result['score'], 4)}, start: {result['start']}, end: {result['end']}")
#result = question_answerer(question="What is a good example of a question answering dataset?", context=context)
#print(f"Answer: '{result['answer']}', score: {round(result['score'], 4)}, start: {result['start']}, end: {result['end']}")
def qa_func(paragraph, question):
#return model.predict(paragraph, question)["answer"]
return result['answer']
iface = gr.Interface(qa_func,
[
gr.inputs.Textbox(lines=7, label="Context", default=context),
gr.inputs.Textbox(lines=1, label="Question", default="What is extractive question answering?"),
],
gr.outputs.Textbox(label="Answer"))
iface.launch(share=True)
"""
import os, sys
file_folder = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(file_folder, "utils"))
from bert import QA
model = QA('bert-large-uncased-whole-word-masking-finetuned-squad')
def qa_func(paragraph, question):
return model.predict(paragraph, question)["answer"]
iface = gr.Interface(qa_func,
[
gr.inputs.Textbox(lines=7, label="Context", default="Victoria has a written constitution enacted in 1975, but based on the 1855 colonial constitution, passed by the United Kingdom Parliament as the Victoria Constitution Act 1855, which establishes the Parliament as the state's law-making body for matters coming under state responsibility. The Victorian Constitution can be amended by the Parliament of Victoria, except for certain 'entrenched' provisions that require either an absolute majority in both houses, a three-fifths majority in both houses, or the approval of the Victorian people in a referendum, depending on the provision."),
gr.inputs.Textbox(lines=1, label="Question", default="When did Victoria enact its constitution?"),
],
gr.outputs.Textbox(label="Answer"))
iface.launch()
"""
"""
import gradio as gr
def greet(name):
return "Hello " + name + "!!"
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()
""" |