File size: 1,874 Bytes
e64582c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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)