loubnabnl HF staff commited on
Commit
a47d2f3
1 Parent(s): c0ae999

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -12
app.py CHANGED
@@ -10,8 +10,10 @@ from text_generation import Client
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
  API_URL = "https://api-inference.huggingface.co/models/bigcode/starcoder"
14
  API_URL_BASE ="https://api-inference.huggingface.co/models/bigcode/starcoderbase"
 
15
 
16
  FIM_PREFIX = "<fim_prefix>"
17
  FIM_MIDDLE = "<fim_middle>"
@@ -20,30 +22,39 @@ FIM_SUFFIX = "<fim_suffix>"
20
  FIM_INDICATOR = "<FILL_HERE>"
21
 
22
  FORMATS = """## Model Formats
 
23
  The model is pretrained on code and is formatted with special tokens in addition to the pure code data,\
24
  such as prefixes specifying the source of the file or tokens separating code from a commit message.\
25
  Use these templates to explore the model's capacities:
 
26
  ### 1. Prefixes 🏷️
27
  For pure code files, use any combination of the following prefixes:
 
28
  ```
29
  <reponame>REPONAME<filename>FILENAME<gh_stars>STARS\ncode<|endoftext|>
30
  ```
31
  STARS can be one of: 0, 1-10, 10-100, 100-1000, 1000+
 
32
  ### 2. Commits 💾
33
  The commits data is formatted as follows:
 
34
  ```
35
  <commit_before>code<commit_msg>text<commit_after>code<|endoftext|>
36
  ```
 
37
  ### 3. Jupyter Notebooks 📓
38
  The model is trained on Jupyter notebooks as Python scripts and structured formats like:
 
39
  ```
40
  <start_jupyter><jupyter_text>text<jupyter_code>code<jupyter_output>output<jupyter_text>
41
  ```
 
42
  ### 4. Issues 🐛
43
  We also trained on GitHub issues using the following formatting:
44
  ```
45
  <issue_start><issue_comment>text<issue_comment>...<issue_closed>
46
  ```
 
47
  ### 5. Fill-in-the-middle 🧩
48
  Fill in the middle requires rearranging the model inputs. The playground handles this for you - all you need is to specify where to fill:
49
  ```
@@ -71,6 +82,9 @@ client = Client(
71
  client_base = Client(
72
  API_URL_BASE, headers={"Authorization": f"Bearer {HF_TOKEN}"},
73
  )
 
 
 
74
 
75
  def generate(
76
  prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0, version="StarCoder",
@@ -101,6 +115,8 @@ def generate(
101
 
102
  if version == "StarCoder":
103
  stream = client.generate_stream(prompt, **generate_kwargs)
 
 
104
  else:
105
  stream = client_base.generate_stream(prompt, **generate_kwargs)
106
 
@@ -126,6 +142,7 @@ def generate(
126
  examples = [
127
  "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",
128
  "// Returns every other value in the array as a new array.\nfunction everyOther(arr) {",
 
129
  "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",
130
  ]
131
 
@@ -150,9 +167,16 @@ css += share_btn_css + monospace_css + ".gradio-container {color: black}"
150
 
151
  description = """
152
  <div style="text-align: center;">
153
- <h1> 💫 StarCoder<span style='color: #e6b800;'> - </span>Code Completion Playground 🪐</h1>
154
- <p>This is a demo to generate code with <a href="https://huggingface.co/bigcode/starcoder" style='color: #e6b800;'>StarCoder</a>, a 15B parameter model for code generation in 86 programming languages.
155
- <b>This is not an instruction model</b>. For instruction and chatting you can chat with a fine-tuned version of the model at <a href="https://huggingface.co/spaces/HuggingFaceH4/starchat-playground">StarChat Playground</a></p>
 
 
 
 
 
 
 
156
  </div>
157
  """
158
  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>\
@@ -161,15 +185,23 @@ disclaimer = """⚠️<b>Any use or sharing of this demo constitues your accepta
161
  with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
162
  with gr.Column():
163
  gr.Markdown(description)
 
 
 
 
 
 
 
164
  with gr.Row():
165
  with gr.Column():
166
  instruction = gr.Textbox(
167
  placeholder="Enter your code here",
168
- label="Code",
 
169
  elem_id="q-input",
170
  )
171
  submit = gr.Button("Generate", variant="primary")
172
- output = gr.Code(elem_id="q-output", lines=30)
173
  with gr.Row():
174
  with gr.Column():
175
  with gr.Accordion("Advanced settings", open=False):
@@ -213,13 +245,7 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
213
  interactive=True,
214
  info="Penalize repeated tokens",
215
  )
216
- with gr.Column():
217
- version = gr.Dropdown(
218
- ["StarCoderBase", "StarCoder"],
219
- value="StarCoder",
220
- label="Version",
221
- info="",
222
- )
223
  gr.Markdown(disclaimer)
224
  with gr.Group(elem_id="share-btn-container"):
225
  community_icon = gr.HTML(community_icon_html, visible=True)
 
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>"
 
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
  ```
 
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",
 
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
 
 
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
 
 
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>\
 
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="StarCoderPlus",
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):
 
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)