Commit
•
7573abd
0
Parent(s):
Duplicate from bigcode/bigcode-playground
Browse files- .gitattributes +34 -0
- .gitignore +160 -0
- README.md +13 -0
- app.py +271 -0
- requirements.txt +2 -0
- share_btn.py +112 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
*.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
|
15 |
+
*.npz 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 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.pytest_cache/
|
52 |
+
cover/
|
53 |
+
|
54 |
+
# Translations
|
55 |
+
*.mo
|
56 |
+
*.pot
|
57 |
+
|
58 |
+
# Django stuff:
|
59 |
+
*.log
|
60 |
+
local_settings.py
|
61 |
+
db.sqlite3
|
62 |
+
db.sqlite3-journal
|
63 |
+
|
64 |
+
# Flask stuff:
|
65 |
+
instance/
|
66 |
+
.webassets-cache
|
67 |
+
|
68 |
+
# Scrapy stuff:
|
69 |
+
.scrapy
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# PyBuilder
|
75 |
+
.pybuilder/
|
76 |
+
target/
|
77 |
+
|
78 |
+
# Jupyter Notebook
|
79 |
+
.ipynb_checkpoints
|
80 |
+
|
81 |
+
# IPython
|
82 |
+
profile_default/
|
83 |
+
ipython_config.py
|
84 |
+
|
85 |
+
# pyenv
|
86 |
+
# For a library or package, you might want to ignore these files since the code is
|
87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
88 |
+
# .python-version
|
89 |
+
|
90 |
+
# pipenv
|
91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94 |
+
# install all needed dependencies.
|
95 |
+
#Pipfile.lock
|
96 |
+
|
97 |
+
# poetry
|
98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100 |
+
# commonly ignored for libraries.
|
101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102 |
+
#poetry.lock
|
103 |
+
|
104 |
+
# pdm
|
105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106 |
+
#pdm.lock
|
107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108 |
+
# in version control.
|
109 |
+
# https://pdm.fming.dev/#use-with-ide
|
110 |
+
.pdm.toml
|
111 |
+
|
112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
113 |
+
__pypackages__/
|
114 |
+
|
115 |
+
# Celery stuff
|
116 |
+
celerybeat-schedule
|
117 |
+
celerybeat.pid
|
118 |
+
|
119 |
+
# SageMath parsed files
|
120 |
+
*.sage.py
|
121 |
+
|
122 |
+
# Environments
|
123 |
+
.env
|
124 |
+
.venv
|
125 |
+
env/
|
126 |
+
venv/
|
127 |
+
ENV/
|
128 |
+
env.bak/
|
129 |
+
venv.bak/
|
130 |
+
|
131 |
+
# Spyder project settings
|
132 |
+
.spyderproject
|
133 |
+
.spyproject
|
134 |
+
|
135 |
+
# Rope project settings
|
136 |
+
.ropeproject
|
137 |
+
|
138 |
+
# mkdocs documentation
|
139 |
+
/site
|
140 |
+
|
141 |
+
# mypy
|
142 |
+
.mypy_cache/
|
143 |
+
.dmypy.json
|
144 |
+
dmypy.json
|
145 |
+
|
146 |
+
# Pyre type checker
|
147 |
+
.pyre/
|
148 |
+
|
149 |
+
# pytype static type analyzer
|
150 |
+
.pytype/
|
151 |
+
|
152 |
+
# Cython debug symbols
|
153 |
+
cython_debug/
|
154 |
+
|
155 |
+
# PyCharm
|
156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
+
#.idea/
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: BigCode - Playground
|
3 |
+
emoji: 🪐
|
4 |
+
colorFrom: grey
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.28.3
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: bigcode/bigcode-playground
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
import shutil
|
4 |
+
import requests
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
from huggingface_hub import Repository
|
8 |
+
from text_generation import Client
|
9 |
+
|
10 |
+
from share_btn import community_icon_html, loading_icon_html, share_js, share_btn_css
|
11 |
+
|
12 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
13 |
+
|
14 |
+
API_URL = "https://api-inference.huggingface.co/models/bigcode/starcoder"
|
15 |
+
API_URL_BASE ="https://api-inference.huggingface.co/models/bigcode/starcoderbase"
|
16 |
+
API_URL_PLUS = "https://api-inference.huggingface.co/models/bigcode/starcoderplus"
|
17 |
+
|
18 |
+
FIM_PREFIX = "<fim_prefix>"
|
19 |
+
FIM_MIDDLE = "<fim_middle>"
|
20 |
+
FIM_SUFFIX = "<fim_suffix>"
|
21 |
+
|
22 |
+
FIM_INDICATOR = "<FILL_HERE>"
|
23 |
+
|
24 |
+
FORMATS = """## Model Formats
|
25 |
+
|
26 |
+
The model is pretrained on code and is formatted with special tokens in addition to the pure code data,\
|
27 |
+
such as prefixes specifying the source of the file or tokens separating code from a commit message.\
|
28 |
+
Use these templates to explore the model's capacities:
|
29 |
+
|
30 |
+
### 1. Prefixes 🏷️
|
31 |
+
For pure code files, use any combination of the following prefixes:
|
32 |
+
|
33 |
+
```
|
34 |
+
<reponame>REPONAME<filename>FILENAME<gh_stars>STARS\ncode<|endoftext|>
|
35 |
+
```
|
36 |
+
STARS can be one of: 0, 1-10, 10-100, 100-1000, 1000+
|
37 |
+
|
38 |
+
### 2. Commits 💾
|
39 |
+
The commits data is formatted as follows:
|
40 |
+
|
41 |
+
```
|
42 |
+
<commit_before>code<commit_msg>text<commit_after>code<|endoftext|>
|
43 |
+
```
|
44 |
+
|
45 |
+
### 3. Jupyter Notebooks 📓
|
46 |
+
The model is trained on Jupyter notebooks as Python scripts and structured formats like:
|
47 |
+
|
48 |
+
```
|
49 |
+
<start_jupyter><jupyter_text>text<jupyter_code>code<jupyter_output>output<jupyter_text>
|
50 |
+
```
|
51 |
+
|
52 |
+
### 4. Issues 🐛
|
53 |
+
We also trained on GitHub issues using the following formatting:
|
54 |
+
```
|
55 |
+
<issue_start><issue_comment>text<issue_comment>...<issue_closed>
|
56 |
+
```
|
57 |
+
|
58 |
+
### 5. Fill-in-the-middle 🧩
|
59 |
+
Fill in the middle requires rearranging the model inputs. The playground handles this for you - all you need is to specify where to fill:
|
60 |
+
```
|
61 |
+
code before<FILL_HERE>code after
|
62 |
+
```
|
63 |
+
"""
|
64 |
+
|
65 |
+
theme = gr.themes.Monochrome(
|
66 |
+
primary_hue="indigo",
|
67 |
+
secondary_hue="blue",
|
68 |
+
neutral_hue="slate",
|
69 |
+
radius_size=gr.themes.sizes.radius_sm,
|
70 |
+
font=[
|
71 |
+
gr.themes.GoogleFont("Open Sans"),
|
72 |
+
"ui-sans-serif",
|
73 |
+
"system-ui",
|
74 |
+
"sans-serif",
|
75 |
+
],
|
76 |
+
)
|
77 |
+
|
78 |
+
client = Client(
|
79 |
+
API_URL,
|
80 |
+
headers={"Authorization": f"Bearer {HF_TOKEN}"},
|
81 |
+
)
|
82 |
+
client_base = Client(
|
83 |
+
API_URL_BASE, headers={"Authorization": f"Bearer {HF_TOKEN}"},
|
84 |
+
)
|
85 |
+
client_plus = Client(
|
86 |
+
API_URL_PLUS, headers={"Authorization": f"Bearer {HF_TOKEN}"},
|
87 |
+
)
|
88 |
+
|
89 |
+
def generate(
|
90 |
+
prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0, version="StarCoder",
|
91 |
+
):
|
92 |
+
|
93 |
+
temperature = float(temperature)
|
94 |
+
if temperature < 1e-2:
|
95 |
+
temperature = 1e-2
|
96 |
+
top_p = float(top_p)
|
97 |
+
fim_mode = False
|
98 |
+
|
99 |
+
generate_kwargs = dict(
|
100 |
+
temperature=temperature,
|
101 |
+
max_new_tokens=max_new_tokens,
|
102 |
+
top_p=top_p,
|
103 |
+
repetition_penalty=repetition_penalty,
|
104 |
+
do_sample=True,
|
105 |
+
seed=42,
|
106 |
+
)
|
107 |
+
|
108 |
+
if FIM_INDICATOR in prompt:
|
109 |
+
fim_mode = True
|
110 |
+
try:
|
111 |
+
prefix, suffix = prompt.split(FIM_INDICATOR)
|
112 |
+
except:
|
113 |
+
raise ValueError(f"Only one {FIM_INDICATOR} allowed in prompt!")
|
114 |
+
prompt = f"{FIM_PREFIX}{prefix}{FIM_SUFFIX}{suffix}{FIM_MIDDLE}"
|
115 |
+
|
116 |
+
if version == "StarCoder":
|
117 |
+
stream = client.generate_stream(prompt, **generate_kwargs)
|
118 |
+
elif version == "StarCoderPlus":
|
119 |
+
stream = client_plus.generate_stream(prompt, **generate_kwargs)
|
120 |
+
else:
|
121 |
+
stream = client_base.generate_stream(prompt, **generate_kwargs)
|
122 |
+
|
123 |
+
if fim_mode:
|
124 |
+
output = prefix
|
125 |
+
else:
|
126 |
+
output = prompt
|
127 |
+
|
128 |
+
previous_token = ""
|
129 |
+
for response in stream:
|
130 |
+
if response.token.text == "<|endoftext|>":
|
131 |
+
if fim_mode:
|
132 |
+
output += suffix
|
133 |
+
else:
|
134 |
+
return output
|
135 |
+
else:
|
136 |
+
output += response.token.text
|
137 |
+
previous_token = response.token.text
|
138 |
+
yield output
|
139 |
+
return output
|
140 |
+
|
141 |
+
|
142 |
+
examples = [
|
143 |
+
"X_train, y_train, X_test, y_test = train_test_split(X, y, test_size=0.1)\n\n# Train a logistic regression model, predict the labels on the test set and compute the accuracy score",
|
144 |
+
"// Returns every other value in the array as a new array.\nfunction everyOther(arr) {",
|
145 |
+
"Poor English: She no went to the market. Corrected English:",
|
146 |
+
"def alternating(list1, list2):\n results = []\n for i in range(min(len(list1), len(list2))):\n results.append(list1[i])\n results.append(list2[i])\n if len(list1) > len(list2):\n <FILL_HERE>\n else:\n results.extend(list2[i+1:])\n return results",
|
147 |
+
]
|
148 |
+
|
149 |
+
|
150 |
+
def process_example(args):
|
151 |
+
for x in generate(args):
|
152 |
+
pass
|
153 |
+
return x
|
154 |
+
|
155 |
+
|
156 |
+
css = ".generating {visibility: hidden}"
|
157 |
+
|
158 |
+
monospace_css = """
|
159 |
+
#q-input textarea {
|
160 |
+
font-family: monospace, 'Consolas', Courier, monospace;
|
161 |
+
}
|
162 |
+
"""
|
163 |
+
|
164 |
+
|
165 |
+
css += share_btn_css + monospace_css + ".gradio-container {color: black}"
|
166 |
+
|
167 |
+
|
168 |
+
description = """
|
169 |
+
<div style="text-align: center;">
|
170 |
+
<h1> ⭐ StarCoder <span style='color: #e6b800;'>Models</span> Playground</h1>
|
171 |
+
</div>
|
172 |
+
<div style="text-align: left;">
|
173 |
+
<p>This is a demo to generate text and code with the following StarCoder models:</p>
|
174 |
+
<ul>
|
175 |
+
<li><a href="https://huggingface.co/bigcode/starcoderplus" style='color: #e6b800;'>StarCoderPlus</a>: A finetuned version of StarCoderBase on English web data, making it strong in both English text and code generation.</li>
|
176 |
+
<li><a href="https://huggingface.co/bigcode/starcoderbase" style='color: #e6b800;'>StarCoderBase</a>: A code generation model trained on 80+ programming languages, providing broad language coverage for code generation tasks.</li>
|
177 |
+
<li><a href="https://huggingface.co/bigcode/starcoder" style='color: #e6b800;'>StarCoder</a>: A finetuned version of StarCoderBase specifically focused on Python, while also maintaining strong performance on other programming languages.</li>
|
178 |
+
</ul>
|
179 |
+
<p><b>Please note:</b> These models are not designed for instruction purposes. If you're looking for instruction or want to chat with a fine-tuned model, you can visit the <a href="https://huggingface.co/spaces/HuggingFaceH4/starchat-playground">StarChat Playground</a>.</p>
|
180 |
+
</div>
|
181 |
+
"""
|
182 |
+
disclaimer = """⚠️<b>Any use or sharing of this demo constitues your acceptance of the BigCode [OpenRAIL-M](https://huggingface.co/spaces/bigcode/bigcode-model-license-agreement) License Agreement and the use restrictions included within.</b>\
|
183 |
+
<br>**Intended Use**: this app and its [supporting model](https://huggingface.co/bigcode) are provided for demonstration purposes; not to serve as replacement for human expertise. For more details on the model's limitations in terms of factuality and biases, see the [model card.](hf.co/bigcode)"""
|
184 |
+
|
185 |
+
with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
|
186 |
+
with gr.Column():
|
187 |
+
gr.Markdown(description)
|
188 |
+
with gr.Row():
|
189 |
+
version = gr.Dropdown(
|
190 |
+
["StarCoderPlus", "StarCoderBase", "StarCoder"],
|
191 |
+
value="StarCoder",
|
192 |
+
label="Model",
|
193 |
+
info="Choose a model from the list",
|
194 |
+
)
|
195 |
+
with gr.Row():
|
196 |
+
with gr.Column():
|
197 |
+
instruction = gr.Textbox(
|
198 |
+
placeholder="Enter your code here",
|
199 |
+
lines=5,
|
200 |
+
label="Input",
|
201 |
+
elem_id="q-input",
|
202 |
+
)
|
203 |
+
submit = gr.Button("Generate", variant="primary")
|
204 |
+
output = gr.Code(elem_id="q-output", lines=30, label="Output")
|
205 |
+
with gr.Row():
|
206 |
+
with gr.Column():
|
207 |
+
with gr.Accordion("Advanced settings", open=False):
|
208 |
+
with gr.Row():
|
209 |
+
column_1, column_2 = gr.Column(), gr.Column()
|
210 |
+
with column_1:
|
211 |
+
temperature = gr.Slider(
|
212 |
+
label="Temperature",
|
213 |
+
value=0.2,
|
214 |
+
minimum=0.0,
|
215 |
+
maximum=1.0,
|
216 |
+
step=0.05,
|
217 |
+
interactive=True,
|
218 |
+
info="Higher values produce more diverse outputs",
|
219 |
+
)
|
220 |
+
max_new_tokens = gr.Slider(
|
221 |
+
label="Max new tokens",
|
222 |
+
value=256,
|
223 |
+
minimum=0,
|
224 |
+
maximum=8192,
|
225 |
+
step=64,
|
226 |
+
interactive=True,
|
227 |
+
info="The maximum numbers of new tokens",
|
228 |
+
)
|
229 |
+
with column_2:
|
230 |
+
top_p = gr.Slider(
|
231 |
+
label="Top-p (nucleus sampling)",
|
232 |
+
value=0.90,
|
233 |
+
minimum=0.0,
|
234 |
+
maximum=1,
|
235 |
+
step=0.05,
|
236 |
+
interactive=True,
|
237 |
+
info="Higher values sample more low-probability tokens",
|
238 |
+
)
|
239 |
+
repetition_penalty = gr.Slider(
|
240 |
+
label="Repetition penalty",
|
241 |
+
value=1.2,
|
242 |
+
minimum=1.0,
|
243 |
+
maximum=2.0,
|
244 |
+
step=0.05,
|
245 |
+
interactive=True,
|
246 |
+
info="Penalize repeated tokens",
|
247 |
+
)
|
248 |
+
|
249 |
+
gr.Markdown(disclaimer)
|
250 |
+
with gr.Group(elem_id="share-btn-container"):
|
251 |
+
community_icon = gr.HTML(community_icon_html, visible=True)
|
252 |
+
loading_icon = gr.HTML(loading_icon_html, visible=True)
|
253 |
+
share_button = gr.Button(
|
254 |
+
"Share to community", elem_id="share-btn", visible=True
|
255 |
+
)
|
256 |
+
gr.Examples(
|
257 |
+
examples=examples,
|
258 |
+
inputs=[instruction],
|
259 |
+
cache_examples=False,
|
260 |
+
fn=process_example,
|
261 |
+
outputs=[output],
|
262 |
+
)
|
263 |
+
gr.Markdown(FORMATS)
|
264 |
+
|
265 |
+
submit.click(
|
266 |
+
generate,
|
267 |
+
inputs=[instruction, temperature, max_new_tokens, top_p, repetition_penalty, version],
|
268 |
+
outputs=[output],
|
269 |
+
)
|
270 |
+
share_button.click(None, [], [], _js=share_js)
|
271 |
+
demo.queue(concurrency_count=16).launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
huggingface_hub
|
2 |
+
text-generation==0.4.1
|
share_btn.py
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
community_icon_html = """<svg id="share-btn-share-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32">
|
2 |
+
<path d="M20.6081 3C21.7684 3 22.8053 3.49196 23.5284 4.38415C23.9756 4.93678 24.4428 5.82749 24.4808 7.16133C24.9674 7.01707 25.4353 6.93643 25.8725 6.93643C26.9833 6.93643 27.9865 7.37587 28.696 8.17411C29.6075 9.19872 30.0124 10.4579 29.8361 11.7177C29.7523 12.3177 29.5581 12.8555 29.2678 13.3534C29.8798 13.8646 30.3306 14.5763 30.5485 15.4322C30.719 16.1032 30.8939 17.5006 29.9808 18.9403C30.0389 19.0342 30.0934 19.1319 30.1442 19.2318C30.6932 20.3074 30.7283 21.5229 30.2439 22.6548C29.5093 24.3704 27.6841 25.7219 24.1397 27.1727C21.9347 28.0753 19.9174 28.6523 19.8994 28.6575C16.9842 29.4379 14.3477 29.8345 12.0653 29.8345C7.87017 29.8345 4.8668 28.508 3.13831 25.8921C0.356375 21.6797 0.754104 17.8269 4.35369 14.1131C6.34591 12.058 7.67023 9.02782 7.94613 8.36275C8.50224 6.39343 9.97271 4.20438 12.4172 4.20438H12.4179C12.6236 4.20438 12.8314 4.2214 13.0364 4.25468C14.107 4.42854 15.0428 5.06476 15.7115 6.02205C16.4331 5.09583 17.134 4.359 17.7682 3.94323C18.7242 3.31737 19.6794 3 20.6081 3ZM20.6081 5.95917C20.2427 5.95917 19.7963 6.1197 19.3039 6.44225C17.7754 7.44319 14.8258 12.6772 13.7458 14.7131C13.3839 15.3952 12.7655 15.6837 12.2086 15.6837C11.1036 15.6837 10.2408 14.5497 12.1076 13.1085C14.9146 10.9402 13.9299 7.39584 12.5898 7.1776C12.5311 7.16799 12.4731 7.16355 12.4172 7.16355C11.1989 7.16355 10.6615 9.33114 10.6615 9.33114C10.6615 9.33114 9.0863 13.4148 6.38031 16.206C3.67434 18.998 3.5346 21.2388 5.50675 24.2246C6.85185 26.2606 9.42666 26.8753 12.0653 26.8753C14.8021 26.8753 17.6077 26.2139 19.1799 25.793C19.2574 25.7723 28.8193 22.984 27.6081 20.6107C27.4046 20.212 27.0693 20.0522 26.6471 20.0522C24.9416 20.0522 21.8393 22.6726 20.5057 22.6726C20.2076 22.6726 19.9976 22.5416 19.9116 22.222C19.3433 20.1173 28.552 19.2325 27.7758 16.1839C27.639 15.6445 27.2677 15.4256 26.746 15.4263C24.4923 15.4263 19.4358 19.5181 18.3759 19.5181C18.2949 19.5181 18.2368 19.4937 18.2053 19.4419C17.6743 18.557 17.9653 17.9394 21.7082 15.6009C25.4511 13.2617 28.0783 11.8545 26.5841 10.1752C26.4121 9.98141 26.1684 9.8956 25.8725 9.8956C23.6001 9.89634 18.2311 14.9403 18.2311 14.9403C18.2311 14.9403 16.7821 16.496 15.9057 16.496C15.7043 16.496 15.533 16.4139 15.4169 16.2112C14.7956 15.1296 21.1879 10.1286 21.5484 8.06535C21.7928 6.66715 21.3771 5.95917 20.6081 5.95917Z" fill="#FF9D00"></path>
|
3 |
+
<path d="M5.50686 24.2246C3.53472 21.2387 3.67446 18.9979 6.38043 16.206C9.08641 13.4147 10.6615 9.33111 10.6615 9.33111C10.6615 9.33111 11.2499 6.95933 12.59 7.17757C13.93 7.39581 14.9139 10.9401 12.1069 13.1084C9.29997 15.276 12.6659 16.7489 13.7459 14.713C14.8258 12.6772 17.7747 7.44316 19.304 6.44221C20.8326 5.44128 21.9089 6.00204 21.5484 8.06532C21.188 10.1286 14.795 15.1295 15.4171 16.2118C16.0391 17.2934 18.2312 14.9402 18.2312 14.9402C18.2312 14.9402 25.0907 8.49588 26.5842 10.1752C28.0776 11.8545 25.4512 13.2616 21.7082 15.6008C17.9646 17.9393 17.6744 18.557 18.2054 19.4418C18.7372 20.3266 26.9998 13.1351 27.7759 16.1838C28.5513 19.2324 19.3434 20.1173 19.9117 22.2219C20.48 24.3274 26.3979 18.2382 27.6082 20.6107C28.8193 22.9839 19.2574 25.7722 19.18 25.7929C16.0914 26.62 8.24723 28.3726 5.50686 24.2246Z" fill="#FFD21E"></path>
|
4 |
+
</svg>"""
|
5 |
+
|
6 |
+
loading_icon_html = """<svg id="share-btn-loading-icon" style="display:none;" class="animate-spin"
|
7 |
+
style="color: #ffffff;
|
8 |
+
"
|
9 |
+
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" fill="none" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><circle style="opacity: 0.25;" cx="12" cy="12" r="10" stroke="white" stroke-width="4"></circle><path style="opacity: 0.75;" fill="white" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>"""
|
10 |
+
|
11 |
+
share_js = """async () => {
|
12 |
+
async function uploadFile(file){
|
13 |
+
const UPLOAD_URL = 'https://huggingface.co/uploads';
|
14 |
+
const response = await fetch(UPLOAD_URL, {
|
15 |
+
method: 'POST',
|
16 |
+
headers: {
|
17 |
+
'Content-Type': file.type,
|
18 |
+
'X-Requested-With': 'XMLHttpRequest',
|
19 |
+
},
|
20 |
+
body: file, /// <- File inherits from Blob
|
21 |
+
});
|
22 |
+
const url = await response.text();
|
23 |
+
return url;
|
24 |
+
}
|
25 |
+
|
26 |
+
async function getInputImgFile(imgEl){
|
27 |
+
const res = await fetch(imgEl.src);
|
28 |
+
const blob = await res.blob();
|
29 |
+
const imgId = Date.now() % 200;
|
30 |
+
const isPng = imgEl.src.startsWith(`data:image/png`);
|
31 |
+
if(isPng){
|
32 |
+
const fileName = `sd-perception-${{imgId}}.png`;
|
33 |
+
return new File([blob], fileName, { type: 'image/png' });
|
34 |
+
}else{
|
35 |
+
const fileName = `sd-perception-${{imgId}}.jpg`;
|
36 |
+
return new File([blob], fileName, { type: 'image/jpeg' });
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
// const gradioEl = document.querySelector('body > gradio-app');
|
41 |
+
const gradioEl = document.querySelector("gradio-app");
|
42 |
+
const inputTxt = gradioEl.querySelector('#q-input textarea').value;
|
43 |
+
let outputTxt = gradioEl.querySelector('#q-output .codemirror-wrapper .cm-scroller > div:nth-of-type(2)').innerText;
|
44 |
+
outputTxt = `<pre>${outputTxt}</pre>`
|
45 |
+
|
46 |
+
const titleLength = 150;
|
47 |
+
let titleTxt = inputTxt;
|
48 |
+
if(titleTxt.length > titleLength){
|
49 |
+
titleTxt = titleTxt.slice(0, titleLength) + ' ...';
|
50 |
+
}
|
51 |
+
|
52 |
+
const shareBtnEl = gradioEl.querySelector('#share-btn');
|
53 |
+
const shareIconEl = gradioEl.querySelector('#share-btn-share-icon');
|
54 |
+
const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon');
|
55 |
+
|
56 |
+
if(!inputTxt || !outputTxt){
|
57 |
+
return;
|
58 |
+
};
|
59 |
+
|
60 |
+
shareBtnEl.style.pointerEvents = 'none';
|
61 |
+
shareIconEl.style.display = 'none';
|
62 |
+
loadingIconEl.style.removeProperty('display');
|
63 |
+
|
64 |
+
const descriptionMd = `### Question:
|
65 |
+
${inputTxt}
|
66 |
+
|
67 |
+
### Answer:
|
68 |
+
|
69 |
+
${outputTxt}`;
|
70 |
+
|
71 |
+
const params = {
|
72 |
+
title: titleTxt,
|
73 |
+
description: descriptionMd,
|
74 |
+
};
|
75 |
+
|
76 |
+
const paramsStr = Object.entries(params)
|
77 |
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
78 |
+
.join('&');
|
79 |
+
|
80 |
+
window.open(`https://huggingface.co/spaces/bigcode/bigcode-playground/discussions/new?${paramsStr}`, '_blank');
|
81 |
+
|
82 |
+
shareBtnEl.style.removeProperty('pointer-events');
|
83 |
+
shareIconEl.style.removeProperty('display');
|
84 |
+
loadingIconEl.style.display = 'none';
|
85 |
+
}"""
|
86 |
+
|
87 |
+
share_btn_css = """
|
88 |
+
a {text-decoration-line: underline; font-weight: 600;}
|
89 |
+
.animate-spin {
|
90 |
+
animation: spin 1s linear infinite;
|
91 |
+
}
|
92 |
+
@keyframes spin {
|
93 |
+
from { transform: rotate(0deg); }
|
94 |
+
to { transform: rotate(360deg); }
|
95 |
+
}
|
96 |
+
#share-btn-container {
|
97 |
+
display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
|
98 |
+
}
|
99 |
+
#share-btn {
|
100 |
+
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;
|
101 |
+
}
|
102 |
+
#share-btn * {
|
103 |
+
all: unset;
|
104 |
+
}
|
105 |
+
#share-btn-container div:nth-child(-n+2){
|
106 |
+
width: auto !important;
|
107 |
+
min-height: 0px !important;
|
108 |
+
}
|
109 |
+
#share-btn-container .wrap {
|
110 |
+
display: none !important;
|
111 |
+
}
|
112 |
+
"""
|