Spaces:
Runtime error
Runtime error
Duplicate from THUDM/CodeGeeX
Browse filesCo-authored-by: Qinkai Zheng <[email protected]>
- .gitattributes +31 -0
- README.md +14 -0
- app.py +112 -0
- example_inputs.jsonl +15 -0
.gitattributes
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
23 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: CodeGeeX
|
3 |
+
emoji: 💻
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: gray
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.4
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
duplicated_from: THUDM/CodeGeeX
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_length": 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 |
+
"""
|
59 |
+
<img src="https://raw.githubusercontent.com/THUDM/CodeGeeX/main/resources/logo/codegeex_logo.png">
|
60 |
+
""")
|
61 |
+
gr.Markdown(
|
62 |
+
"""
|
63 |
+
<p align="center">
|
64 |
+
🏠 <a href="https://codegeex.cn" target="_blank">Homepage</a> | 📖 <a href="http://keg.cs.tsinghua.edu.cn/codegeex/" target="_blank">Blog</a> | 🪧 <a href="https://codegeex.cn/playground" target="_blank">DEMO</a> | 🛠 <a href="https://marketplace.visualstudio.com/items?itemName=aminer.codegeex" target="_blank">VS Code</a> or <a href="https://plugins.jetbrains.com/plugin/20587-codegeex" target="_blank">Jetbrains</a> Extensions | 💻 <a href="https://github.com/THUDM/CodeGeeX" target="_blank">Source code</a> | 🤖 <a href="https://models.aminer.cn/codegeex/download/request" target="_blank">Download Model</a>
|
65 |
+
</p>
|
66 |
+
""")
|
67 |
+
gr.Markdown(
|
68 |
+
"""
|
69 |
+
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 supports 15+ programming languages for both code generation and 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://codegeex.cn). We also offer free [VS Code](https://marketplace.visualstudio.com/items?itemName=aminer.codegeex) or [Jetbrains](https://plugins.jetbrains.com/plugin/20587-codegeex) extensions for full functionality.
|
70 |
+
""")
|
71 |
+
|
72 |
+
with gr.Row():
|
73 |
+
with gr.Column():
|
74 |
+
prompt = gr.Textbox(lines=13, placeholder='Please enter the description or select an example input below.',label='Input')
|
75 |
+
with gr.Row():
|
76 |
+
gen = gr.Button("Generate")
|
77 |
+
clr = gr.Button("Clear")
|
78 |
+
|
79 |
+
outputs = gr.Textbox(lines=15, label='Output')
|
80 |
+
|
81 |
+
gr.Markdown(
|
82 |
+
"""
|
83 |
+
Generation Parameter
|
84 |
+
""")
|
85 |
+
with gr.Row():
|
86 |
+
with gr.Column():
|
87 |
+
lang = gr.Radio(
|
88 |
+
choices=["C++", "C", "C#", "Python", "Java", "HTML", "PHP", "JavaScript", "TypeScript", "Go",
|
89 |
+
"Rust",
|
90 |
+
"SQL", "Kotlin", "R", "Fortran"], value='lang', label='Programming Language',
|
91 |
+
default="Python")
|
92 |
+
with gr.Column():
|
93 |
+
seed = gr.Slider(maximum=10000, value=8888, step=1, label='Seed')
|
94 |
+
with gr.Row():
|
95 |
+
out_seq_length = gr.Slider(maximum=1024, value=128, minimum=1, step=1, label='Output Sequence Length')
|
96 |
+
temperature = gr.Slider(maximum=1, value=0.2, minimum=0, label='Temperature')
|
97 |
+
with gr.Row():
|
98 |
+
top_k = gr.Slider(maximum=40, value=0, minimum=0, step=1, label='Top K')
|
99 |
+
top_p = gr.Slider(maximum=1, value=1.0, minimum=0, label='Top P')
|
100 |
+
|
101 |
+
inputs = [prompt, lang, seed, out_seq_length, temperature, top_k, top_p]
|
102 |
+
gen.click(fn=predict, inputs=inputs, outputs=outputs)
|
103 |
+
clr.click(fn=lambda value: gr.update(value=""), inputs=clr, outputs=prompt)
|
104 |
+
|
105 |
+
gr_examples = gr.Examples(examples=examples, inputs=[prompt, lang],
|
106 |
+
label="Example Inputs (Click to insert an examplet it into the input box)",
|
107 |
+
examples_per_page=20)
|
108 |
+
|
109 |
+
demo.launch()
|
110 |
+
|
111 |
+
if __name__ == '__main__':
|
112 |
+
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"}
|