stmnk commited on
Commit
2b7da55
·
1 Parent(s): 932f413

add code t5 structure

Browse files
Files changed (1) hide show
  1. app.py +14 -53
app.py CHANGED
@@ -1,61 +1,22 @@
 
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(share=True)
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"))
37
- from bert import QA
38
-
39
- model = QA('bert-large-uncased-whole-word-masking-finetuned-squad')
40
- def qa_func(paragraph, question):
41
- return model.predict(paragraph, question)["answer"]
42
 
43
  iface = gr.Interface(qa_func,
44
  [
45
- 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."),
46
- gr.inputs.Textbox(lines=1, label="Question", default="When did Victoria enact its constitution?"),
47
  ],
48
- gr.outputs.Textbox(label="Answer"))
49
- iface.launch()
50
-
51
- """
52
-
53
- """
54
- import gradio as gr
55
-
56
- def greet(name):
57
- return "Hello " + name + "!!"
58
-
59
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
60
- iface.launch()
61
- """
 
1
+ import json
2
  import gradio as gr
3
+ import requests as req
4
 
5
+ code_nl = "function for db connection"
6
 
7
+ CT5_URL = "https://api-inference.huggingface.co/models/deepset/roberta-base-squad2"
8
+ CT5_METHOD = 'POST'
9
 
10
+ def pygen_func(code_nl):
11
+ inputs = {'code_nl': code_nl}
12
+ payload = json.dumps(inputs)
13
+ prediction = req.request(CT5_METHOD, CT5_URL, data=payload)
14
+ answer = json.loads(prediction.content.decode("utf-8"))
15
+ return 'BOOM!'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  iface = gr.Interface(qa_func,
18
  [
19
+ gr.inputs.Textbox(lines=7, label="Context", default=code_nl),
 
20
  ],
21
+ gr.outputs.Textbox(label="Completion"))
22
+ iface.launch(share=True)