Makhinur commited on
Commit
d306f59
Β·
verified Β·
1 Parent(s): 790a199

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -1,9 +1,11 @@
 
1
  from typing import Iterator
2
 
3
  import gradio as gr
4
- import torch
5
 
6
- from model import get_input_token_length, run
 
 
7
 
8
  DEFAULT_SYSTEM_PROMPT = """\
9
  You are a helpful, respectful and honest assistant with a deep knowledge of code and software design. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.\
@@ -13,16 +15,14 @@ DEFAULT_MAX_NEW_TOKENS = 1024
13
  MAX_INPUT_TOKEN_LENGTH = 4000
14
 
15
  DESCRIPTION = """
16
- # Code Llama 13B Chat
17
 
18
- This Space demonstrates model [CodeLlama-13b-Instruct](https://huggingface.co/codellama/CodeLlama-13b-Instruct-hf) by Meta, a Code Llama model with 13B parameters fine-tuned for chat instructions and specialized on code tasks. Feel free to play with it, or duplicate to run generations without a queue! If you want to run your own service, you can also [deploy the model on Inference Endpoints](https://huggingface.co/inference-endpoints).
19
 
20
  πŸ”Ž For more details about the Code Llama family of models and how to use them with `transformers`, take a look [at our blog post](https://huggingface.co/blog/codellama) or [the paper](https://huggingface.co/papers/2308.12950).
21
 
22
  πŸƒπŸ» Check out our [Playground](https://huggingface.co/spaces/codellama/codellama-playground) for a super-fast code completion demo that leverages a streaming [inference endpoint](https://huggingface.co/inference-endpoints).
23
 
24
- πŸ’ͺ For a chat demo of the largest Code Llama model (34B parameters), you can [select Code Llama in Hugging Chat!](https://huggingface.co/chat/)
25
-
26
  """
27
 
28
  LICENSE = """
@@ -30,12 +30,9 @@ LICENSE = """
30
 
31
  ---
32
  As a derivate work of Code Llama by Meta,
33
- this demo is governed by the original [license](https://huggingface.co/spaces/huggingface-projects/codellama-2-13b-chat/blob/main/LICENSE.txt) and [acceptable use policy](https://huggingface.co/spaces/huggingface-projects/codellama-2-13b-chat/blob/main/USE_POLICY.md).
34
  """
35
 
36
- if not torch.cuda.is_available():
37
- DESCRIPTION += '\n<p>Running on CPU πŸ₯Ά This demo does not work on CPU.</p>'
38
-
39
 
40
  def clear_and_save_textbox(message: str) -> tuple[str, str]:
41
  return '', message
@@ -55,7 +52,6 @@ def delete_prev_fn(
55
  message = ''
56
  return history, message or ''
57
 
58
-
59
  def generate(
60
  message: str,
61
  history_with_input: list[tuple[str, str]],
@@ -87,7 +83,7 @@ def process_example(message: str) -> tuple[str, list[tuple[str, str]]]:
87
 
88
 
89
  def check_input_token_length(message: str, chat_history: list[tuple[str, str]], system_prompt: str) -> None:
90
- input_token_length = get_input_token_length(message, chat_history, system_prompt)
91
  if input_token_length > MAX_INPUT_TOKEN_LENGTH:
92
  raise gr.Error(f'The accumulated input is too long ({input_token_length} > {MAX_INPUT_TOKEN_LENGTH}). Clear your chat history and try again.')
93
 
@@ -149,8 +145,8 @@ with gr.Blocks(css='style.css') as demo:
149
  step=1,
150
  value=10,
151
  )
152
-
153
- gr.Examples(
154
  examples=[
155
  'What is the Fibonacci sequence?',
156
  'Can you explain briefly what Python is good for?',
@@ -276,4 +272,4 @@ with gr.Blocks(css='style.css') as demo:
276
  api_name=False,
277
  )
278
 
279
- demo.queue(max_size=20).launch()
 
1
+ import os
2
  from typing import Iterator
3
 
4
  import gradio as gr
 
5
 
6
+ from model import run
7
+
8
+ HF_PUBLIC = os.environ.get("HF_PUBLIC", False)
9
 
10
  DEFAULT_SYSTEM_PROMPT = """\
11
  You are a helpful, respectful and honest assistant with a deep knowledge of code and software design. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.\
 
15
  MAX_INPUT_TOKEN_LENGTH = 4000
16
 
17
  DESCRIPTION = """
18
+ # Code Llama 34B Chat
19
 
20
+ This Space demonstrates model [CodeLlama-34b-Instruct](https://huggingface.co/codellama/CodeLlama-34b-Instruct-hf) by Meta, a Code Llama model with 34B parameters fine-tuned for chat instructions and specialized on code tasks. Feel free to play with it, or duplicate to run generations without a queue! If you want to run your own service, you can also [deploy the model on Inference Endpoints](https://huggingface.co/inference-endpoints).
21
 
22
  πŸ”Ž For more details about the Code Llama family of models and how to use them with `transformers`, take a look [at our blog post](https://huggingface.co/blog/codellama) or [the paper](https://huggingface.co/papers/2308.12950).
23
 
24
  πŸƒπŸ» Check out our [Playground](https://huggingface.co/spaces/codellama/codellama-playground) for a super-fast code completion demo that leverages a streaming [inference endpoint](https://huggingface.co/inference-endpoints).
25
 
 
 
26
  """
27
 
28
  LICENSE = """
 
30
 
31
  ---
32
  As a derivate work of Code Llama by Meta,
33
+ this demo is governed by the original [license](https://huggingface.co/spaces/huggingface-projects/codellama-2-34b-chat/blob/main/LICENSE.txt) and [acceptable use policy](https://huggingface.co/spaces/huggingface-projects/codellama-2-34b-chat/blob/main/USE_POLICY.md).
34
  """
35
 
 
 
 
36
 
37
  def clear_and_save_textbox(message: str) -> tuple[str, str]:
38
  return '', message
 
52
  message = ''
53
  return history, message or ''
54
 
 
55
  def generate(
56
  message: str,
57
  history_with_input: list[tuple[str, str]],
 
83
 
84
 
85
  def check_input_token_length(message: str, chat_history: list[tuple[str, str]], system_prompt: str) -> None:
86
+ input_token_length = len(message) + len(chat_history)
87
  if input_token_length > MAX_INPUT_TOKEN_LENGTH:
88
  raise gr.Error(f'The accumulated input is too long ({input_token_length} > {MAX_INPUT_TOKEN_LENGTH}). Clear your chat history and try again.')
89
 
 
145
  step=1,
146
  value=10,
147
  )
148
+
149
+ gr.Examples(
150
  examples=[
151
  'What is the Fibonacci sequence?',
152
  'Can you explain briefly what Python is good for?',
 
272
  api_name=False,
273
  )
274
 
275
+ demo.queue(max_size=32).launch(share=HF_PUBLIC)