Duplicate from codeparrot/codeparrot-subspace
Browse filesCo-authored-by: loubna ben allal <loubnabnl@users.noreply.huggingface.co>
- .gitattributes +27 -0
- README.md +13 -0
- app.py +57 -0
- requirements.txt +3 -0
.gitattributes
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
19 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Codeparrot Subspace
|
3 |
+
emoji: ๐ฆ
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.0.4
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: codeparrot/codeparrot-subspace
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, set_seed, pipeline
|
3 |
+
|
4 |
+
#https://huggingface.co/spaces/lvwerra/codeparrot-generation
|
5 |
+
|
6 |
+
title = "CodeParrot Generator ๐ฆ"
|
7 |
+
description = "This is a subspace to make code generation with [CodeParrot](https://huggingface.co/lvwerra/codeparrot), it is used in a larger [space](https://huggingface.co/spaces/loubnabnl/Code-generation-models-v1) for model comparison. For more flexibilty in sampling, you can find another demo for CodeParrot [here](https://huggingface.co/spaces/lvwerra/codeparrot-generation)."
|
8 |
+
example = [
|
9 |
+
["def print_hello_world():", 8, 0.6, 42],
|
10 |
+
["def get_file_size(filepath):", 40, 0.6, 42],
|
11 |
+
["def count_lines(filename):", 40, 0.6, 42],
|
12 |
+
["def count_words(filename):", 40, 0.6, 42]]
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained("codeparrot/codeparrot")
|
14 |
+
model = AutoModelForCausalLM.from_pretrained("codeparrot/codeparrot", low_cpu_mem_usage=True)
|
15 |
+
|
16 |
+
|
17 |
+
def code_generation(gen_prompt, max_tokens, temperature=0.6, seed=42):
|
18 |
+
set_seed(seed)
|
19 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
20 |
+
generated_text = pipe(gen_prompt, do_sample=True, top_p=0.95, temperature=temperature, max_new_tokens=max_tokens)[0]['generated_text']
|
21 |
+
return generated_text
|
22 |
+
|
23 |
+
|
24 |
+
iface = gr.Interface(
|
25 |
+
fn=code_generation,
|
26 |
+
inputs=[
|
27 |
+
gr.Textbox(lines=10, label="Input code"),
|
28 |
+
gr.inputs.Slider(
|
29 |
+
minimum=8,
|
30 |
+
maximum=256,
|
31 |
+
step=1,
|
32 |
+
default=8,
|
33 |
+
label="Number of tokens to generate",
|
34 |
+
),
|
35 |
+
gr.inputs.Slider(
|
36 |
+
minimum=0,
|
37 |
+
maximum=2,
|
38 |
+
step=0.1,
|
39 |
+
default=0.6,
|
40 |
+
label="Temperature",
|
41 |
+
),
|
42 |
+
gr.inputs.Slider(
|
43 |
+
minimum=0,
|
44 |
+
maximum=1000,
|
45 |
+
step=1,
|
46 |
+
default=42,
|
47 |
+
label="Random seed to use for the generation"
|
48 |
+
)
|
49 |
+
],
|
50 |
+
outputs=gr.Textbox(label="Predicted code", lines=10),
|
51 |
+
examples=example,
|
52 |
+
layout="horizontal",
|
53 |
+
theme="peach",
|
54 |
+
description=description,
|
55 |
+
title=title
|
56 |
+
)
|
57 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers==4.19.0
|
2 |
+
accelerate==0.10.0
|
3 |
+
torch==1.11.0
|