pygen / app.py
stmnk's picture
add req data
4bebae2
raw
history blame
1.17 kB
import json
import gradio as gr
import requests as req
code_nl = "function for db connection"
CT5_URL = "https://api-inference.huggingface.co/models/nielsr/codet5-small-code-summarization-ruby"
CT5_METHOD = 'POST'
API_URL = CT5_URL
headers = {"Authorization": "Bearer api_UhCKXKyqxJOpOcbvrZurQFqmVNZRTtxVfl"}
def query(payload):
response = req.post(API_URL, headers=headers, json=payload)
return response.json()
function_code = 'inputs: def pad(tensor, paddings, mode: "CONSTANT", name: nil) _op(:pad, tensor, paddings, mode: mode, name: name) end </s>'
req_data = {"inputs": function_code}
output = query(req_data)
def pygen_func(code_nl):
inputs = {'code_nl': code_nl}
# payload = json.dumps(inputs)
# prediction = req.request(CT5_METHOD, CT5_URL, data=payload)
# prediction = req.request(CT5_METHOD, CT5_URL, json=req_data)
# answer = json.loads(prediction.content.decode("utf-8"))
return 'BOOM! ' + output # + ' BOOM!!: ' + answer
iface = gr.Interface(pygen_func,
[
gr.inputs.Textbox(lines=7, label="Code Intent NL", default=code_nl),
],
gr.outputs.Textbox(label="Code Generated PL"))
iface.launch(share=True)