Spaces:
Runtime error
Runtime error
Diego ROJAS
commited on
Commit
β’
57d3d9b
1
Parent(s):
0bc7713
Update demo for CodeGeeX4 release
Browse files- .gitattributes +5 -1
- README.md +1 -1
- app.py +44 -96
- example_inputs.jsonl +0 -15
- requirements.txt +1 -0
.gitattributes
CHANGED
@@ -2,11 +2,13 @@
|
|
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
|
@@ -14,14 +16,16 @@
|
|
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
|
|
|
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 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
*.npy filter=lfs diff=lfs merge=lfs -text
|
|
|
16 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
*.pkl filter=lfs diff=lfs merge=lfs -text
|
|
|
22 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
*.wasm filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: π»
|
|
4 |
colorFrom: gray
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
|
|
4 |
colorFrom: gray
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.36.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
app.py
CHANGED
@@ -1,112 +1,60 @@
|
|
1 |
-
import json
|
2 |
import os
|
3 |
-
|
4 |
import gradio as gr
|
5 |
-
import
|
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 |
-
|
19 |
|
20 |
-
|
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 |
-
|
37 |
-
|
38 |
-
except Exception as e:
|
39 |
-
return 'Timeout! Please wait a few minutes and retry'
|
40 |
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
|
46 |
-
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
|
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 |
-
|
57 |
-
|
58 |
"""
|
59 |
-
<
|
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 |
-
|
68 |
-
|
69 |
-
|
70 |
-
"""
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
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()
|
|
|
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
+
from openai import OpenAI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
SYSTEM_PROMPT = "You are an intelligent programming assistant named CodeGeeX. You will answer any questions users have about programming, coding, and computers, and provide code that is formatted correctly, executable, accurate, and secure, and offer detailed explanations when necessary."
|
6 |
|
7 |
+
client = OpenAI(base_url="https://api.chatglm.cn/v1", api_key=os.getenv("CHATGLM_API_KEY"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
|
|
|
|
|
|
9 |
|
10 |
+
def respond(message, history: list[tuple[str, str]]):
|
11 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
|
|
|
|
12 |
|
13 |
+
for val in history:
|
14 |
+
if val[0]:
|
15 |
+
messages.append({"role": "user", "content": val[0]})
|
16 |
+
if val[1]:
|
17 |
+
messages.append({"role": "assistant", "content": val[1]})
|
18 |
|
19 |
+
messages.append({"role": "user", "content": message})
|
20 |
|
21 |
+
response = ""
|
22 |
|
23 |
+
for message in client.chat.completions.create(
|
24 |
+
messages=messages, # type: ignore
|
25 |
+
model="codegeex4-9b-biz",
|
26 |
+
stream=True,
|
27 |
+
temperature=0.7,
|
28 |
+
max_tokens=1024,
|
29 |
+
top_p=0.95,
|
30 |
+
): # type: ignore
|
31 |
+
token = message.choices[0].delta.content
|
32 |
|
33 |
+
response += token
|
34 |
+
yield response
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
with gr.Blocks(fill_height=True) as demo:
|
37 |
+
gr.Markdown(
|
38 |
"""
|
39 |
+
<p align="center" style="margin: 32px 32px 0 0;">
|
40 |
+
<img src="https://gist.githubusercontent.com/rojas-diego/0c1b444aff2c6b6420ff635bfd206869/raw/16566317fabce71d35ab3cf8c71adf3b5dc11d87/codegeex.svg" style="width: 30%">
|
|
|
|
|
|
|
|
|
41 |
</p>
|
42 |
""")
|
43 |
+
gr.Markdown(
|
44 |
+
"""
|
45 |
+
<p align="center">
|
46 |
+
π <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://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/CodeGeeX4" target="_blank">Github</a> | π€ <a href="https://huggingface.co/THUDM/codegeex-4-9b" target="_blank">HuggingFace</a>
|
47 |
+
</p>
|
48 |
+
""")
|
49 |
+
gr.Markdown(
|
50 |
+
"""
|
51 |
+
<p align="center">
|
52 |
+
We introduce CodeGeeX4 9B, a large-scale multilingual code generation model with 9 billion parameters, pre-trained on a large code corpus of more than 300 programming languages. CodeGeeX4 9B is open source, please refer to our <a href="https://github.com/THUDM/codegeex-4-9b" target="_blank">GitHub</a> for more details. We also offer free <a href="https://marketplace.visualstudio.com/items?itemName=aminer.codegeex" target="_blank">VS Code</a> and <a href="https://plugins.jetbrains.com/plugin/20587-codegeex" target="_blank">Jetbrains</a> extensions for full functionality.
|
53 |
+
</p>
|
54 |
+
""")
|
55 |
+
|
56 |
+
gr.ChatInterface(respond, fill_height=True)
|
57 |
+
|
58 |
+
|
59 |
+
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
demo.launch()
|
|
|
|
|
|
example_inputs.jsonl
DELETED
@@ -1,15 +0,0 @@
|
|
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"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
openai==1.35.10
|