lewtun HF staff commited on
Commit
b85d14b
1 Parent(s): 2194771

Add starchat beta

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +32 -13
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: ⭐️💬
4
  colorFrom: pink
5
  colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 3.28.3
8
  app_file: app.py
9
  pinned: true
10
  license: mit
 
4
  colorFrom: pink
5
  colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 3.34.0
8
  app_file: app.py
9
  pinned: true
10
  license: mit
app.py CHANGED
@@ -13,12 +13,12 @@ from share_btn import (community_icon_html, loading_icon_html, share_btn_css,
13
 
14
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
15
  API_TOKEN = os.environ.get("API_TOKEN", None)
16
- API_URL = os.environ.get("API_URL", None)
17
 
18
- client = Client(
19
- API_URL,
20
- headers={"Authorization": f"Bearer {API_TOKEN}"},
21
- )
 
22
 
23
  repo = None
24
  if HF_TOKEN:
@@ -28,12 +28,15 @@ if HF_TOKEN:
28
  pass
29
 
30
  repo = Repository(
31
- local_dir="./data/", clone_from="HuggingFaceH4/starchat-prompts", use_auth_token=HF_TOKEN, repo_type="dataset"
 
 
 
32
  )
33
  repo.git_pull()
34
 
35
 
36
- def save_inputs_and_outputs(now, inputs, outputs, generate_kwargs):
37
  current_hour = now.strftime("%Y-%m-%d_%H")
38
  file_name = f"prompts_{current_hour}.jsonl"
39
 
@@ -41,7 +44,9 @@ def save_inputs_and_outputs(now, inputs, outputs, generate_kwargs):
41
  repo.git_pull(rebase=True)
42
  with open(os.path.join("data", file_name), "a", encoding="utf-8") as f:
43
  json.dump(
44
- {"inputs": inputs, "outputs": outputs, "generate_kwargs": generate_kwargs}, f, ensure_ascii=False
 
 
45
  )
46
  f.write("\n")
47
  repo.push_to_hub()
@@ -72,6 +77,7 @@ def has_no_history(chatbot, history):
72
 
73
 
74
  def generate(
 
75
  system_message,
76
  user_message,
77
  chatbot,
@@ -83,6 +89,10 @@ def generate(
83
  repetition_penalty,
84
  do_save=True,
85
  ):
 
 
 
 
86
  # Don't return meaningless message when the input is empty
87
  if not user_message:
88
  print("Empty input")
@@ -155,7 +165,7 @@ def generate(
155
  now = datetime.datetime.now()
156
  current_time = now.strftime("%Y-%m-%d %H:%M:%S")
157
  print(f"[{current_time}] Pushing prompt and completion to the Hub")
158
- save_inputs_and_outputs(now, prompt, output, generate_kwargs)
159
  except Exception as e:
160
  print(e)
161
 
@@ -207,15 +217,15 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
207
  with gr.Column():
208
  gr.Markdown(
209
  """
210
- 💻 This demo showcases an **alpha** version of **[StarChat](https://huggingface.co/HuggingFaceH4/starchat-alpha)**, a variant of **[StarCoderBase](https://huggingface.co/bigcode/starcoderbase)** that was fine-tuned on the [Dolly](https://huggingface.co/datasets/databricks/databricks-dolly-15k) and [OpenAssistant](https://huggingface.co/datasets/OpenAssistant/oasst1) datasets to act as a helpful coding assistant. The base model has 16B parameters and was pretrained on one trillion tokens sourced from 80+ programming languages, GitHub issues, Git commits, and Jupyter notebooks (all permissively licensed).
211
 
212
  📝 For more details, check out our [blog post](https://huggingface.co/blog/starchat-alpha).
213
 
214
- ⚠️ **Intended Use**: this app and its [supporting model](https://huggingface.co/HuggingFaceH4/starchat-alpha) are provided as educational tools to explain large language model fine-tuning; not to serve as replacement for human expertise.
215
 
216
- ⚠️ **Known Failure Modes**: this alpha version of **StarChat** has not been aligned to human preferences with techniques like RLHF, so the model can produce problematic outputs (especially when prompted to do so). Since the base model was pretrained on a large corpus of code, it may produce code snippets that are syntactically valid but semantically incorrect. For example, it may produce code that does not compile or that produces incorrect results. It may also produce code that is vulnerable to security exploits. We have observed the model also has a tendency to produce false URLs which should be carefully inspected before clicking. For more details on the model's limitations in terms of factuality and biases, see the [model card](https://huggingface.co/HuggingFaceH4/starchat-alpha#bias-risks-and-limitations).
217
 
218
- ⚠️ **Data Collection**: by default, we are collecting the prompts entered in this app to further improve and evaluate the model. Do **NOT** share any personal or sensitive information while using the app! You can opt out of this data collection by removing the checkbox below.
219
  """
220
  )
221
 
@@ -225,6 +235,10 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
225
  label="Store data",
226
  info="You agree to the storage of your prompt and generated text for research and development purposes:",
227
  )
 
 
 
 
228
  with gr.Accordion(label="System Prompt", open=False, elem_id="parameters-accordion"):
229
  system_message = gr.Textbox(
230
  elem_id="system-message",
@@ -312,6 +326,7 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
312
  user_message.submit(
313
  generate,
314
  inputs=[
 
315
  system_message,
316
  user_message,
317
  chatbot,
@@ -324,11 +339,13 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
324
  do_save,
325
  ],
326
  outputs=[chatbot, history, last_user_message, user_message],
 
327
  )
328
 
329
  send_button.click(
330
  generate,
331
  inputs=[
 
332
  system_message,
333
  user_message,
334
  chatbot,
@@ -341,9 +358,11 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
341
  do_save,
342
  ],
343
  outputs=[chatbot, history, last_user_message, user_message],
 
344
  )
345
 
346
  clear_chat_button.click(clear_chat, outputs=[chatbot, history])
 
347
  # share_button.click(None, [], [], _js=share_js)
348
 
349
  demo.queue(concurrency_count=16).launch(debug=True)
 
13
 
14
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
15
  API_TOKEN = os.environ.get("API_TOKEN", None)
 
16
 
17
+ model2endpoint = {
18
+ "starchat-alpha": "https://api-inference.huggingface.co/models/HuggingFaceH4/starcoderbase-finetuned-oasst1",
19
+ "starchat-beta": "https://ddimh86h0wqthbhy.us-east-1.aws.endpoints.huggingface.cloud",
20
+ }
21
+ model_names = list(model2endpoint.keys())
22
 
23
  repo = None
24
  if HF_TOKEN:
 
28
  pass
29
 
30
  repo = Repository(
31
+ local_dir="./data/",
32
+ clone_from="HuggingFaceH4/starchat_playground_dialogues",
33
+ use_auth_token=HF_TOKEN,
34
+ repo_type="dataset",
35
  )
36
  repo.git_pull()
37
 
38
 
39
+ def save_inputs_and_outputs(now, inputs, outputs, generate_kwargs, model):
40
  current_hour = now.strftime("%Y-%m-%d_%H")
41
  file_name = f"prompts_{current_hour}.jsonl"
42
 
 
44
  repo.git_pull(rebase=True)
45
  with open(os.path.join("data", file_name), "a", encoding="utf-8") as f:
46
  json.dump(
47
+ {"model": model, "inputs": inputs, "outputs": outputs, "generate_kwargs": generate_kwargs},
48
+ f,
49
+ ensure_ascii=False,
50
  )
51
  f.write("\n")
52
  repo.push_to_hub()
 
77
 
78
 
79
  def generate(
80
+ model_name,
81
  system_message,
82
  user_message,
83
  chatbot,
 
89
  repetition_penalty,
90
  do_save=True,
91
  ):
92
+ client = Client(
93
+ model2endpoint[model_name],
94
+ headers={"Authorization": f"Bearer {API_TOKEN}"},
95
+ )
96
  # Don't return meaningless message when the input is empty
97
  if not user_message:
98
  print("Empty input")
 
165
  now = datetime.datetime.now()
166
  current_time = now.strftime("%Y-%m-%d %H:%M:%S")
167
  print(f"[{current_time}] Pushing prompt and completion to the Hub")
168
+ save_inputs_and_outputs(now, prompt, output, generate_kwargs, model_name)
169
  except Exception as e:
170
  print(e)
171
 
 
217
  with gr.Column():
218
  gr.Markdown(
219
  """
220
+ 💻 This demo showcases a series of **[StarChat](https://huggingface.co/models?search=huggingfaceh4/starchat)** language models, which are fine-tuned versions of the StarCoder family to act as helpful coding assistants. The base model has 16B parameters and was pretrained on one trillion tokens sourced from 80+ programming languages, GitHub issues, Git commits, and Jupyter notebooks (all permissively licensed).
221
 
222
  📝 For more details, check out our [blog post](https://huggingface.co/blog/starchat-alpha).
223
 
224
+ ⚠️ **Intended Use**: this app and its [supporting models](https://huggingface.co/models?search=huggingfaceh4/starchat) are provided as educational tools to explain large language model fine-tuning; not to serve as replacement for human expertise.
225
 
226
+ ⚠️ **Known Failure Modes**: the alpha and beta version of **StarChat** have not been aligned to human preferences with techniques like RLHF, so they can produce problematic outputs (especially when prompted to do so). Since the base model was pretrained on a large corpus of code, it may produce code snippets that are syntactically valid but semantically incorrect. For example, it may produce code that does not compile or that produces incorrect results. It may also produce code that is vulnerable to security exploits. We have observed the model also has a tendency to produce false URLs which should be carefully inspected before clicking. For more details on the model's limitations in terms of factuality and biases, see the [model card](https://huggingface.co/HuggingFaceH4/starchat-alpha#bias-risks-and-limitations).
227
 
228
+ ⚠️ **Data Collection**: by default, we are collecting the prompts entered in this app to further improve and evaluate the models. Do **NOT** share any personal or sensitive information while using the app! You can opt out of this data collection by removing the checkbox below.
229
  """
230
  )
231
 
 
235
  label="Store data",
236
  info="You agree to the storage of your prompt and generated text for research and development purposes:",
237
  )
238
+
239
+ with gr.Row():
240
+ selected_model = gr.Radio(choices=model_names, value=model_names[1], label="Select a model")
241
+
242
  with gr.Accordion(label="System Prompt", open=False, elem_id="parameters-accordion"):
243
  system_message = gr.Textbox(
244
  elem_id="system-message",
 
326
  user_message.submit(
327
  generate,
328
  inputs=[
329
+ selected_model,
330
  system_message,
331
  user_message,
332
  chatbot,
 
339
  do_save,
340
  ],
341
  outputs=[chatbot, history, last_user_message, user_message],
342
+ show_progress=False,
343
  )
344
 
345
  send_button.click(
346
  generate,
347
  inputs=[
348
+ selected_model,
349
  system_message,
350
  user_message,
351
  chatbot,
 
358
  do_save,
359
  ],
360
  outputs=[chatbot, history, last_user_message, user_message],
361
+ show_progress=False,
362
  )
363
 
364
  clear_chat_button.click(clear_chat, outputs=[chatbot, history])
365
+ selected_model.change(clear_chat, outputs=[chatbot, history])
366
  # share_button.click(None, [], [], _js=share_js)
367
 
368
  demo.queue(concurrency_count=16).launch(debug=True)