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() output = query({"inputs": "The answer to the universe is"}) 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={"inputs": "The answer to the universe is"}) 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)