import os import requests import gradio as gr # ENV vars API_URL = os.environ["API_URL"] HF_TOKEN = os.environ["HF_TOKEN"] headers = {"Authorization": f"Bearer {HF_TOKEN}"} comment_syntaxes = { "C": "/* {} */", "C++": "/* {} */", "Java": "/* {} */", "Golang": "/* {} */", "Rust": "/* {} */", "Javascript": "/* {} */", "PHP": "/* {} */", "Kotlin": "/* {} */", "HTML": "", "Python": "#{}", "Bash": "#{}", "Ruby": "=begin {} =end", } def get_script(lang, instruction): jsn = {"inputs": comment_syntaxes[lang].format("instruction: " + instruction), "parameters": { "top_p": 0.9, "max_new_tokens": 64, "return_full_text": True, "do_sample": True, }, "options": {"use_cache": True, "wait_for_model": True, }, } response = requests.post(API_URL, headers=headers, json=jsn) return response.json()["generated_text"] demo = gr.Blocks() with demo: gr.Markdown( "