Spaces:
Runtime error
Runtime error
abdulmeLINK
commited on
Commit
•
e64582c
1
Parent(s):
9b13739
app.py upload
Browse files
README.md
CHANGED
@@ -7,7 +7,8 @@ sdk: gradio
|
|
7 |
sdk_version: 3.1.4
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
|
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
7 |
sdk_version: 3.1.4
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
models:
|
11 |
+
- bigscience/bloom
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
|
6 |
+
# ENV vars
|
7 |
+
API_URL = os.environ["API_URL"]
|
8 |
+
HF_TOKEN = os.environ["HF_TOKEN"]
|
9 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
10 |
+
|
11 |
+
comment_syntaxes = {
|
12 |
+
"C": "/* {} */",
|
13 |
+
"C++": "/* {} */",
|
14 |
+
"Java": "/* {} */",
|
15 |
+
"Golang": "/* {} */",
|
16 |
+
"Rust": "/* {} */",
|
17 |
+
"Javascript": "/* {} */",
|
18 |
+
"PHP": "/* {} */",
|
19 |
+
"Kotlin": "/* {} */",
|
20 |
+
"HTML": "<!-- {} -->",
|
21 |
+
"Python": "#{}",
|
22 |
+
"Bash": "#{}",
|
23 |
+
"Ruby": "=begin {} =end",
|
24 |
+
}
|
25 |
+
|
26 |
+
|
27 |
+
def get_script(lang, instruction):
|
28 |
+
jsn = {"inputs": comment_syntaxes[lang].format("instruction: " + instruction),
|
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(
|
52 |
+
choices=comment_syntaxes.keys(), label="Choose the language")
|
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 with ascii characters ", lines=6)
|
57 |
+
|
58 |
+
with gr.Row():
|
59 |
+
generated_txt = gr.Textbox(lines=5)
|
60 |
+
|
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 |
+
"![visitor badge](https://visitor-badge.glitch.me/badge?page_id=abdulmeLINK.programmer-bloom)")
|
68 |
+
|
69 |
+
demo.launch(enable_queue=True, debug=True)
|