stmnk commited on
Commit
65ad43e
·
1 Parent(s): 33b3e10

add trans qa

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -1,4 +1,36 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import os, sys
3
  file_folder = os.path.dirname(os.path.abspath(__file__))
4
  sys.path.insert(0, os.path.join(file_folder, "utils"))
@@ -16,6 +48,8 @@ iface = gr.Interface(qa_func,
16
  gr.outputs.Textbox(label="Answer"))
17
  iface.launch()
18
 
 
 
19
  """
20
  import gradio as gr
21
 
 
1
  import gradio as gr
2
+
3
+ from transformers import pipeline
4
+
5
+ question_answerer = pipeline("question-answering")
6
+
7
+ context = r"""
8
+ Extractive Question Answering is the task of extracting an answer from a text given a question. An example of a
9
+ question answering dataset is the SQuAD dataset, which is entirely based on that task. If you would like to fine-tune
10
+ a model on a SQuAD task, you may leverage the examples/pytorch/question-answering/run_squad.py script.
11
+ """
12
+
13
+ result = question_answerer(question="What is extractive question answering?", context=context)
14
+ print(f"Answer: '{result['answer']}', score: {round(result['score'], 4)}, start: {result['start']}, end: {result['end']}")
15
+
16
+ #result = question_answerer(question="What is a good example of a question answering dataset?", context=context)
17
+ #print(f"Answer: '{result['answer']}', score: {round(result['score'], 4)}, start: {result['start']}, end: {result['end']}")
18
+
19
+ def qa_func(paragraph, question):
20
+ #return model.predict(paragraph, question)["answer"]
21
+ return result['answer']
22
+
23
+ iface = gr.Interface(qa_func,
24
+ [
25
+ gr.inputs.Textbox(lines=7, label="Context", default=context),
26
+ gr.inputs.Textbox(lines=1, label="Question", default="What is extractive question answering?"),
27
+ ],
28
+ gr.outputs.Textbox(label="Answer"))
29
+ iface.launch()
30
+
31
+
32
+ """
33
+
34
  import os, sys
35
  file_folder = os.path.dirname(os.path.abspath(__file__))
36
  sys.path.insert(0, os.path.join(file_folder, "utils"))
 
48
  gr.outputs.Textbox(label="Answer"))
49
  iface.launch()
50
 
51
+ """
52
+
53
  """
54
  import gradio as gr
55