Spaces:
Runtime error
Runtime error
add code t5 structure
Browse files
app.py
CHANGED
@@ -1,61 +1,22 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
|
5 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
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=
|
46 |
-
gr.inputs.Textbox(lines=1, label="Question", default="When did Victoria enact its constitution?"),
|
47 |
],
|
48 |
-
gr.outputs.Textbox(label="
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|