Stanislas commited on
Commit
e278e9e
1 Parent(s): 999c11f

Initial commit

Browse files
Files changed (3) hide show
  1. README.md +2 -2
  2. app.py +102 -0
  3. example_inputs.jsonl +15 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: CodeGeeX
3
- emoji: 🦀
4
  colorFrom: blue
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 3.4
8
  app_file: app.py
1
  ---
2
  title: CodeGeeX
3
+ emoji: 💻
4
  colorFrom: blue
5
+ colorTo: white
6
  sdk: gradio
7
  sdk_version: 3.4
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+
4
+ import gradio as gr
5
+ import requests
6
+
7
+ APIKEY = os.environ.get("APIKEY")
8
+ APISECRET = os.environ.get("APISECRET")
9
+
10
+
11
+ def predict(prompt, lang, seed, out_seq_length, temperature, top_k, top_p):
12
+ global APIKEY
13
+ global APISECRET
14
+
15
+ if prompt == '':
16
+ return 'Input should not be empty!'
17
+
18
+ url = 'https://tianqi.aminer.cn/api/v2/multilingual_code_generate_block'
19
+
20
+ payload = json.dumps({
21
+ "apikey" : APIKEY,
22
+ "apisecret" : APISECRET,
23
+ "prompt" : prompt,
24
+ "lang" : lang,
25
+ "out_seq_lengt": out_seq_length,
26
+ "seed" : seed,
27
+ "temperature" : temperature,
28
+ "top_k" : top_k,
29
+ "top_p" : top_p
30
+ })
31
+
32
+ headers = {
33
+ 'Content-Type': 'application/json'
34
+ }
35
+
36
+ try:
37
+ response = requests.request("POST", url, headers=headers, data=payload, timeout=(20, 100)).json()
38
+ except Exception as e:
39
+ return 'Timeout! Please wait a few minutes and retry'
40
+
41
+ if response['status'] == 1:
42
+ return response['message']
43
+
44
+ answer = response['result']['output']['code'][0]
45
+
46
+ return prompt + answer
47
+
48
+
49
+ def main():
50
+ gr.close_all()
51
+ examples = []
52
+ with open("./example_inputs.jsonl", "r") as f:
53
+ for line in f:
54
+ examples.append(list(json.loads(line).values()))
55
+
56
+ with gr.Blocks() as demo:
57
+ gr.Markdown(
58
+ """# CodeGeeX: A Multilingual Code Generation Model
59
+ <img src="https://github.com/THUDM/CodeGeeX/blob/main/resources/logo/codegeex_logo.png">
60
+ We introduce CodeGeeX, a large-scale multilingual code generation model with 13 billion parameters, pre-trained on a large code corpus of more than 20 programming languages. CodeGeeX was trained on more than 850 billion tokens on a cluster of 1,536 [Ascend 910 AI Processors](https://e.huawei.com/en/products/servers/ascend). CodeGeeX supports 15+ programming languages for both code generation and code translation. CodeGeeX is open source, please refer to our [GitHub](https://github.com/THUDM/CodeGeeX) for more details. This is a minimal-functional DEMO, for other DEMOs like code translation, please visit our [Homepage](https://models.aminer.cn/codegeex/). We also offer a free [VS Code extension](https://marketplace.visualstudio.com/items?itemName=aminer.codegeex) for full functionality.
61
+ """)
62
+
63
+ with gr.Row():
64
+ with gr.Column():
65
+ prompt = gr.Textbox(lines=13, placeholder='Input', label='Input')
66
+ with gr.Row():
67
+ gen = gr.Button("Generate")
68
+ clr = gr.Button("Clear")
69
+
70
+ outputs = gr.Textbox(lines=15, label='Output')
71
+
72
+ gr.Markdown(
73
+ """
74
+ Generation Parameter
75
+ """)
76
+ with gr.Row():
77
+ with gr.Column():
78
+ lang = gr.Radio(
79
+ choices=["C++", "C", "C#", "Python", "Java", "HTML", "PHP", "JavaScript", "TypeScript", "Go",
80
+ "Rust",
81
+ "SQL", "Kotlin", "R", "Fortran"], value='lang', label='Programming Language',
82
+ default="Python")
83
+ with gr.Column():
84
+ seed = gr.Slider(maximum=10000, value=43, step=1, label='Seed')
85
+ out_seq_length = gr.Slider(maximum=1024, value=256, minimum=1, step=1, label='Output Sequence Length')
86
+ temperature = gr.Slider(maximum=1, value=0.9, minimum=0, label='Temperature')
87
+ top_k = gr.Slider(maximum=40, value=0, minimum=0, step=1, label='Top K')
88
+ top_p = gr.Slider(maximum=1, value=1.0, minimum=0, label='Top P')
89
+
90
+ inputs = [prompt, lang, seed, out_seq_length, temperature, top_k, top_p]
91
+ gen.click(fn=predict, inputs=inputs, outputs=outputs)
92
+ clr.click(fn=lambda value: gr.update(value=""), inputs=clr, outputs=prompt)
93
+
94
+ gr_examples = gr.Examples(examples=examples, inputs=[prompt, lang],
95
+ label="Example Inputs (Click to insert an examplet it into the input box)",
96
+ examples_per_page=20)
97
+ gr.Markdown("![visitors](https://visitor-badge.glitch.me/badge?page_id=THUDM.CodeGeeX)")
98
+
99
+ demo.launch()
100
+
101
+ if __name__ == '__main__':
102
+ main()
example_inputs.jsonl ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"code": "# Write a function that returns the sum of the numbers from 1 to n.\n# For example, if n is 5, then the function should return 1 + 2 + 3 + 4 + 5.\n\n# You may assume that n is a positive integer.\ndef sum_of_numbers(n):", "langauge": "Python"}
2
+ {"code": "// Write a function that returns the sum of the numbers from 1 to n.\n// For example, if n is 5, then the function should return 1 + 2 + 3 + 4 + 5.\n\n#include <iostream>\nusing namespace std;\nint sum_of_numbers(int n) {", "langauge": "C++"}
3
+ {"code": "// Write a function that returns the sum of the numbers from 1 to n.\n// For example, if n is 5, then the function should return 1 + 2 + 3 + 4 + 5.\n\n#include <stdio.h>\n#include <stdlib.h>\nint sum(int n)\n{", "langauge": "C"}
4
+ {"code": "// Write a function that returns the sum of the numbers from 1 to n.\n// For example, if n is 5, then the function should return 1 + 2 + 3 + 4 + 5.\nprivate int sum(int n) {", "langauge": "C#"}
5
+ {"code": "// Write a function that returns the sum of the numbers from 1 to n.\n// For example, if n is 5, then the function should return 1 + 2 + 3 + 4 + 5.\n\npublic class SumOfNumbers {", "langauge": "Java"}
6
+ {"code": "<!--Write a homepage of CodeGeeX.-->\n\n<div class=\"container\">", "langauge": "HTML"}
7
+ {"code": "// Write a function that returns the sum of the numbers from 1 to n.\n// For example, if n is 5, then the function should return 1 + 2 + 3 + 4 + 5.\n// If n is 0, then the function should return 0.\n// If n is less than 0, then the function should return -1.\n/**\n * @param {number} n\n * @return {number}\n */\nfunction sum ($n) {", "langauge": "PHP"}
8
+ {"code": "// Write a function that returns the sum of the numbers from 1 to n.\n// For example, if n is 5, then the function should return 1 + 2 + 3 + 4 + 5.\n\nfunction sum(n) {", "langauge": "JavaScript"}
9
+ {"code": "// Write a function that returns the sum of the numbers from 1 to n,\n// but using a for loop instead of a while loop.\n\nfunction sumForLoop(n) {", "langauge": "TypeScript"}
10
+ {"code": "// Write a function that returns the sum of the numbers from 1 to n,\n// but using a for loop instead of a while loop.\n\nfunc sumN(n int) int {", "langauge": "Go"}
11
+ {"code": "// Write a function that returns the sum of the numbers from 1 to n,\n// but using a for loop instead of a while loop.\n\nfn sum_numbers(n: usize) -> usize {", "langauge": "Rust"}
12
+ {"code": "-- Search all the records from the table CodeGeeX\n-- Delete iterms with odd indices", "langauge": "SQL"}
13
+ {"code": "// Write a function that returns the sum of the numbers from 1 to n.\n// For example, if n is 5, then the function should return 1 + 2 + 3 + 4 + 5.\n\nfun sum(n: Int): Int {", "langauge": "Kotlin"}
14
+ {"code": "! Write a function that returns the sum of the numbers from 1 to n.\n! For example, if n is 5, then the function should return 1 + 2 + 3 + 4 + 5.\n\n! Use the following header:\n! module sum_numbers\n! end\nmodule sum_numbers", "langauge": "Fortran"}
15
+ {"code": "# Write a function that returns the sum of the numbers from 1 to n.\n# For example, if n is 5, then the function should return 1 + 2 + 3 + 4 + 5.\nsum_numbers <- function(n) {", "langauge": "R"}