abdulmeLINK's picture
app.py upload
e64582c
raw history blame
No virus
1.87 kB
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(
"<h1><center>Give Instructions to Generate a Program</center></h1>")
with gr.Row():
dropdown = gr.Dropdown(
choices=comment_syntaxes.keys(), label="Choose the language")
# with gr.Column:
instruction = gr.Textbox(label="Write a instruction",
value="Create a python function that generates random password with given length with ascii characters ", lines=6)
with gr.Row():
generated_txt = gr.Textbox(lines=5)
btn = gr.Button("Generate")
btn.click(get_script, inputs=[dropdown,
instruction], outputs=generated_txt)
with gr.Row():
gr.Markdown(
"![visitor badge](https://visitor-badge.glitch.me/badge?page_id=abdulmeLINK.programmer-bloom)")
demo.launch(enable_queue=True, debug=True)