YifengDing commited on
Commit
ff68452
1 Parent(s): 65a009c

feature: add examples

Browse files
Files changed (1) hide show
  1. app.py +50 -28
app.py CHANGED
@@ -7,6 +7,24 @@ import torch
7
  import gradio as gr
8
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def main(
11
  base_model="ise-uiuc/Magicoder-S-DS-6.7B"
12
  ):
@@ -19,13 +37,6 @@ def main(
19
  temperature=1,
20
  max_length=2048,
21
  ):
22
- MAGICODER_PROMPT = """You are an exceptionally intelligent coding assistant that consistently delivers accurate and reliable responses to user instructions.
23
-
24
- @@ Instruction
25
- {instruction}
26
-
27
- @@ Response
28
- """
29
  prompt = MAGICODER_PROMPT.format(instruction=instruction)
30
 
31
  if temperature > 0:
@@ -44,30 +55,41 @@ def main(
44
  generated_text = seq["generated_text"].replace(prompt, "")
45
  return generated_text
46
 
47
- gr.Interface(
48
- fn=evaluate_magicoder,
49
- inputs=[
50
- gr.components.Textbox(
51
- lines=3,
52
- label="Instruction",
53
- placeholder="Anything you want to ask Magicoder ?",
54
- value="Write a snake game in Python using the turtle library (the game is created by Magicoder).",
55
- ),
56
- gr.components.Slider(minimum=0, maximum=1, value=0, label="Temperature"),
57
- gr.components.Slider(
58
- minimum=1, maximum=2048, step=1, value=2048, label="Max tokens"
59
- ),
60
- ],
61
- outputs=[
62
- gr.components.Textbox(
 
 
 
 
 
 
 
 
 
 
63
  lines=30,
64
  label="Output",
65
  )
66
- ],
67
- title="🎩 Magicoder",
68
- 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.",
69
- ).queue().launch()
70
-
 
71
 
72
  if __name__ == "__main__":
73
  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
+
12
+ @@ Instruction
13
+ {instruction}
14
+
15
+ @@ Response
16
+ """
17
+
18
+ title = "<h1 style='text-align: center; margin-bottom: 1rem'>🎩 Magicoder</h1>"
19
+
20
+ 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.
21
+
22
+ 💡 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:
23
+ 1. Specify your programming language (e.g., "... in Python" and "... in Java")
24
+ 2. Specify the external libraries/packages that are necessary in your task (e.g., "... using the turtle library" and "Write a gradio application to ...")
25
+ 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")"""
26
+
27
+
28
  def main(
29
  base_model="ise-uiuc/Magicoder-S-DS-6.7B"
30
  ):
 
37
  temperature=1,
38
  max_length=2048,
39
  ):
 
 
 
 
 
 
 
40
  prompt = MAGICODER_PROMPT.format(instruction=instruction)
41
 
42
  if temperature > 0:
 
55
  generated_text = seq["generated_text"].replace(prompt, "")
56
  return generated_text
57
 
58
+ with gr.Blocks() as demo:
59
+ gr.Markdown(title)
60
+ gr.Markdown(description)
61
+ with gr.Row(equal_height=False):
62
+ with gr.Column(variant="panel"):
63
+ interface_input = gr.Textbox(
64
+ lines=3,
65
+ label="Instruction",
66
+ placeholder="Anything you want to ask Magicoder ?",
67
+ value="Write a snake game in Python using the turtle library (the game is created by Magicoder).",
68
+ )
69
+ temperature = gr.Slider(minimum=0, maximum=1, value=0, label="Temperature")
70
+ max_new_tokens = gr.Slider(
71
+ minimum=1, maximum=2048, step=1, value=2048, label="Max tokens"
72
+ )
73
+ submit = gr.Button("Submit", variant="primary")
74
+ gr.Examples(
75
+ examples=[
76
+ ["Write a snake game in Python using the turtle library (the game is created by Magicoder)."],
77
+ ["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."],
78
+ ["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."],
79
+ ["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."],
80
+ ],
81
+ inputs = [interface_input]
82
+ )
83
+ output = gr.Textbox(
84
  lines=30,
85
  label="Output",
86
  )
87
+ submit.click(
88
+ evaluate_magicoder,
89
+ inputs=[interface_input, temperature, max_new_tokens],
90
+ outputs=[output],
91
+ )
92
+ demo.queue().launch(share=True)
93
 
94
  if __name__ == "__main__":
95
  fire.Fire(main)