Spaces:
Sleeping
Sleeping
elghafiani
commited on
Commit
·
57db60f
1
Parent(s):
7286aab
Updated
Browse files
app.py
CHANGED
@@ -7,29 +7,40 @@ import torch
|
|
7 |
import gradio as gr
|
8 |
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def main(
|
11 |
-
base_model="ise-uiuc/Magicoder-S-DS-6.7B"
|
12 |
-
port=8080,
|
13 |
):
|
14 |
-
tokenizer = AutoTokenizer.from_pretrained(base_model)
|
15 |
pipeline = transformers.pipeline(
|
16 |
-
"text-generation",
|
17 |
-
model=base_model,
|
18 |
-
torch_dtype=torch.float16,
|
19 |
-
device_map="auto"
|
20 |
)
|
|
|
21 |
def evaluate_magicoder(
|
22 |
instruction,
|
23 |
temperature=1,
|
24 |
-
|
25 |
):
|
26 |
-
MAGICODER_PROMPT = """You are an exceptionally intelligent coding assistant that consistently delivers accurate and reliable responses to user instructions.
|
27 |
-
|
28 |
-
@@ Instruction
|
29 |
-
{instruction}
|
30 |
-
|
31 |
-
@@ Response
|
32 |
-
"""
|
33 |
prompt = MAGICODER_PROMPT.format(instruction=instruction)
|
34 |
|
35 |
if temperature > 0:
|
@@ -37,41 +48,53 @@ def main(
|
|
37 |
prompt,
|
38 |
do_sample=True,
|
39 |
temperature=temperature,
|
40 |
-
|
41 |
)
|
42 |
else:
|
43 |
sequences = pipeline(
|
44 |
prompt,
|
45 |
-
|
46 |
)
|
47 |
for seq in sequences:
|
48 |
-
|
49 |
-
print(prompt)
|
50 |
-
generated_text = seq['generated_text'].replace(prompt, "")
|
51 |
-
print('===========================answer=============================')
|
52 |
-
print(generated_text)
|
53 |
return generated_text
|
54 |
|
55 |
-
gr.
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
)
|
71 |
-
|
72 |
-
title="Magicoder",
|
73 |
-
description="This is a LLM playground for Magicoder! Follow us on Github: https://github.com/ise-uiuc/magicoder and Huggingface: https://huggingface.co/ise-uiuc."
|
74 |
-
).queue().launch()
|
75 |
|
76 |
if __name__ == "__main__":
|
77 |
-
fire.Fire(main)
|
|
|
7 |
import gradio as gr
|
8 |
|
9 |
|
10 |
+
MAGICODER_PROMPT = """You are an exceptionally intelligent coding assistant that consistently delivers accurate and reliable responses to user instructions.
|
11 |
+
@@ Instruction
|
12 |
+
{instruction}
|
13 |
+
@@ Response
|
14 |
+
"""
|
15 |
+
|
16 |
+
css = """
|
17 |
+
#q-output {
|
18 |
+
max-height: 60vh;
|
19 |
+
overflow: auto;
|
20 |
+
}
|
21 |
+
"""
|
22 |
+
|
23 |
+
title = "<h1 style='text-align: center; margin-bottom: 1rem'>🎩 Magicoder</h1>"
|
24 |
+
|
25 |
+
description = """This is a playground for Magicoder-S-DS-6.7B! Follow us on Github: https://github.com/ise-uiuc/magicoder and Huggingface: https://huggingface.co/ise-uiuc.
|
26 |
+
💡 Tips: You can include more details in your instruction for Magicoder to write better code for you! Details can be, but not limited to, as follows:
|
27 |
+
1. Specify your programming language (e.g., "... in Python" and "... in Java")
|
28 |
+
2. Specify the external libraries/packages that are necessary in your task (e.g., "... using the turtle library" and "Write a gradio application to ...")
|
29 |
+
3. Demonstrate your requirements as clear and comprehensive as possible (e.g., "use CNN as the model structure" and "draw a chart of the training loss")"""
|
30 |
+
|
31 |
+
|
32 |
def main(
|
33 |
+
base_model="ise-uiuc/Magicoder-S-DS-6.7B"
|
|
|
34 |
):
|
|
|
35 |
pipeline = transformers.pipeline(
|
36 |
+
"text-generation", model=base_model, torch_dtype=torch.bfloat16, device_map="auto"
|
|
|
|
|
|
|
37 |
)
|
38 |
+
|
39 |
def evaluate_magicoder(
|
40 |
instruction,
|
41 |
temperature=1,
|
42 |
+
max_length=2048,
|
43 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
prompt = MAGICODER_PROMPT.format(instruction=instruction)
|
45 |
|
46 |
if temperature > 0:
|
|
|
48 |
prompt,
|
49 |
do_sample=True,
|
50 |
temperature=temperature,
|
51 |
+
max_length=max_length,
|
52 |
)
|
53 |
else:
|
54 |
sequences = pipeline(
|
55 |
prompt,
|
56 |
+
max_length=max_length,
|
57 |
)
|
58 |
for seq in sequences:
|
59 |
+
generated_text = seq["generated_text"].replace(prompt, "")
|
|
|
|
|
|
|
|
|
60 |
return generated_text
|
61 |
|
62 |
+
with gr.Blocks(css=css) as demo:
|
63 |
+
gr.Markdown(title)
|
64 |
+
gr.Markdown(description)
|
65 |
+
with gr.Row(equal_height=True):
|
66 |
+
with gr.Column(variant="default"):
|
67 |
+
interface_input = gr.Textbox(
|
68 |
+
lines=3,
|
69 |
+
label="Instruction",
|
70 |
+
placeholder="Anything you want to ask Magicoder ?",
|
71 |
+
value="Write a snake game in Python using the turtle library (the game is created by Magicoder).",
|
72 |
+
)
|
73 |
+
temperature = gr.Slider(minimum=0, maximum=1, value=0, label="Temperature")
|
74 |
+
max_new_tokens = gr.Slider(
|
75 |
+
minimum=1, maximum=2048, step=1, value=2048, label="Max tokens"
|
76 |
+
)
|
77 |
+
submit = gr.Button(value="Generate")
|
78 |
+
gr.Examples(
|
79 |
+
examples=[
|
80 |
+
["Write a snake game in Python using the turtle library (the game is created by Magicoder)."],
|
81 |
+
["Build a console-based Othello game in Java with row and column numbers shown on the board. The game should end when there are no more valid moves for either player."],
|
82 |
+
["Write a gradio (3.48.0) application for the following use case: Take an input image and return a 45 degree clockwise rotated image. You should also add text description under the output showing the rotation degree."],
|
83 |
+
["Build a simple neural network in Python using Pytorch to classify handwritten digits from the MNIST dataset. You should use CNN as the model structure, train the model for 5 epochs, draw a chart of the training loss, and show the final result."],
|
84 |
+
],
|
85 |
+
inputs = [interface_input]
|
86 |
+
)
|
87 |
+
with gr.Column(variant="default"):
|
88 |
+
with gr.Tab("Output", elem_id="q-output"):
|
89 |
+
output = gr.Markdown(
|
90 |
+
label="Output"
|
91 |
+
)
|
92 |
+
submit.click(
|
93 |
+
evaluate_magicoder,
|
94 |
+
inputs=[interface_input, temperature, max_new_tokens],
|
95 |
+
outputs=[output],
|
96 |
)
|
97 |
+
demo.queue().launch()
|
|
|
|
|
|
|
98 |
|
99 |
if __name__ == "__main__":
|
100 |
+
fire.Fire(main)
|