Spaces:
Runtime error
Runtime error
Commit
·
9152c8d
1
Parent(s):
e64582c
update prompt
Browse files
app.py
CHANGED
|
@@ -23,29 +23,41 @@ comment_syntaxes = {
|
|
| 23 |
"Ruby": "=begin {} =end",
|
| 24 |
}
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
"parameters":
|
| 30 |
-
{
|
| 31 |
-
"top_p": 0.9,
|
| 32 |
-
"max_new_tokens": 64,
|
| 33 |
-
"return_full_text": True,
|
| 34 |
-
"do_sample": True,
|
| 35 |
-
},
|
| 36 |
-
"options":
|
| 37 |
-
{"use_cache": True,
|
| 38 |
-
"wait_for_model": True,
|
| 39 |
-
}, }
|
| 40 |
response = requests.post(API_URL, headers=headers, json=jsn)
|
| 41 |
return response.json()["generated_text"]
|
| 42 |
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
demo = gr.Blocks()
|
| 45 |
|
| 46 |
with demo:
|
| 47 |
gr.Markdown(
|
| 48 |
"<h1><center>Give Instructions to Generate a Program</center></h1>")
|
|
|
|
|
|
|
| 49 |
with gr.Row():
|
| 50 |
|
| 51 |
dropdown = gr.Dropdown(
|
|
@@ -53,7 +65,7 @@ with demo:
|
|
| 53 |
|
| 54 |
# with gr.Column:
|
| 55 |
instruction = gr.Textbox(label="Write a instruction",
|
| 56 |
-
value="Create a python function that generates random password with given length
|
| 57 |
|
| 58 |
with gr.Row():
|
| 59 |
generated_txt = gr.Textbox(lines=5)
|
|
@@ -61,7 +73,9 @@ with demo:
|
|
| 61 |
btn = gr.Button("Generate")
|
| 62 |
btn.click(get_script, inputs=[dropdown,
|
| 63 |
instruction], outputs=generated_txt)
|
| 64 |
-
|
|
|
|
|
|
|
| 65 |
with gr.Row():
|
| 66 |
gr.Markdown(
|
| 67 |
"")
|
|
|
|
| 23 |
"Ruby": "=begin {} =end",
|
| 24 |
}
|
| 25 |
|
| 26 |
+
jsn_trail = {"parameters":
|
| 27 |
+
{
|
| 28 |
+
"top_p": 0.9,
|
| 29 |
+
"max_new_tokens": 64,
|
| 30 |
+
"return_full_text": True,
|
| 31 |
+
"do_sample": True,
|
| 32 |
+
},
|
| 33 |
+
"options":
|
| 34 |
+
{"use_cache": True,
|
| 35 |
+
"wait_for_model": True,
|
| 36 |
+
}, }
|
| 37 |
|
| 38 |
+
|
| 39 |
+
def post(jsn):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
response = requests.post(API_URL, headers=headers, json=jsn)
|
| 41 |
return response.json()["generated_text"]
|
| 42 |
|
| 43 |
|
| 44 |
+
def get_script(lang, instruction):
|
| 45 |
+
jsn = {"inputs": comment_syntaxes[lang].format("Instruction: " + instruction.replace(
|
| 46 |
+
'\n', '')) + '\n' + comment_syntaxes[lang].format("Code:") + '\n'} + jsn_trail
|
| 47 |
+
return post(jsn)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def feedback(opt):
|
| 51 |
+
return post({"inputs": opt} + jsn_trail)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
demo = gr.Blocks()
|
| 55 |
|
| 56 |
with demo:
|
| 57 |
gr.Markdown(
|
| 58 |
"<h1><center>Give Instructions to Generate a Program</center></h1>")
|
| 59 |
+
gr.Markdown(
|
| 60 |
+
"<p>This project aims to prepare a prompt for BLOOM to generate scripts</p>")
|
| 61 |
with gr.Row():
|
| 62 |
|
| 63 |
dropdown = gr.Dropdown(
|
|
|
|
| 65 |
|
| 66 |
# with gr.Column:
|
| 67 |
instruction = gr.Textbox(label="Write a instruction",
|
| 68 |
+
value="Create a python function that generates random password with given length using ascii characters ", lines=6)
|
| 69 |
|
| 70 |
with gr.Row():
|
| 71 |
generated_txt = gr.Textbox(lines=5)
|
|
|
|
| 73 |
btn = gr.Button("Generate")
|
| 74 |
btn.click(get_script, inputs=[dropdown,
|
| 75 |
instruction], outputs=generated_txt)
|
| 76 |
+
feeedback_btn = gr.Button("Feed the Output back")
|
| 77 |
+
feeedback_btn.click(
|
| 78 |
+
feedback, inputs=[generated_txt], outputs=generated_txt)
|
| 79 |
with gr.Row():
|
| 80 |
gr.Markdown(
|
| 81 |
"")
|