botsi commited on
Commit
59b7ed0
·
verified ·
1 Parent(s): 906b1dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -58
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import os
2
  from threading import Thread
3
  from typing import Iterator
@@ -12,34 +14,41 @@ DEFAULT_MAX_NEW_TOKENS = 1024
12
  MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
13
 
14
  DESCRIPTION = """\
15
- # Llama-2 7B Chat
16
-
17
- This Space demonstrates model [Llama-2-7b-chat](https://huggingface.co/meta-llama/Llama-2-7b-chat) by Meta, a Llama 2 model with 7B parameters fine-tuned for chat instructions. 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).
18
-
19
- 🔎 For more details about the Llama 2 family of models and how to use them with `transformers`, take a look [at our blog post](https://huggingface.co/blog/llama2).
20
-
21
- 🔨 Looking for an even more powerful model? Check out the [13B version](https://huggingface.co/spaces/huggingface-projects/llama-2-13b-chat) or the large [70B model demo](https://huggingface.co/spaces/ysharma/Explore_llamav2_with_TGI).
22
  """
23
 
24
- LICENSE = """
25
  <p/>
26
 
27
  ---
28
- As a derivate work of [Llama-2-7b-chat](https://huggingface.co/meta-llama/Llama-2-7b-chat) by Meta,
29
- this demo is governed by the original [license](https://huggingface.co/spaces/huggingface-projects/llama-2-7b-chat/blob/main/LICENSE.txt) and [acceptable use policy](https://huggingface.co/spaces/huggingface-projects/llama-2-7b-chat/blob/main/USE_POLICY.md).
30
  """
31
 
32
  if not torch.cuda.is_available():
33
  DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
34
 
35
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  if torch.cuda.is_available():
37
  model_id = "meta-llama/Llama-2-7b-chat-hf"
38
  model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
39
  tokenizer = AutoTokenizer.from_pretrained(model_id)
40
  tokenizer.use_default_system_prompt = False
41
 
42
-
43
  @spaces.GPU
44
  def generate(
45
  message: str,
@@ -87,59 +96,22 @@ def generate(
87
 
88
  chat_interface = gr.ChatInterface(
89
  fn=generate,
90
- additional_inputs=[
91
- gr.Textbox(label="System prompt", lines=6),
92
- gr.Slider(
93
- label="Max new tokens",
94
- minimum=1,
95
- maximum=MAX_MAX_NEW_TOKENS,
96
- step=1,
97
- value=DEFAULT_MAX_NEW_TOKENS,
98
- ),
99
- gr.Slider(
100
- label="Temperature",
101
- minimum=0.1,
102
- maximum=4.0,
103
- step=0.1,
104
- value=0.6,
105
- ),
106
- gr.Slider(
107
- label="Top-p (nucleus sampling)",
108
- minimum=0.05,
109
- maximum=1.0,
110
- step=0.05,
111
- value=0.9,
112
- ),
113
- gr.Slider(
114
- label="Top-k",
115
- minimum=1,
116
- maximum=1000,
117
- step=1,
118
- value=50,
119
- ),
120
- gr.Slider(
121
- label="Repetition penalty",
122
- minimum=1.0,
123
- maximum=2.0,
124
- step=0.05,
125
- value=1.2,
126
- ),
127
- ],
128
- stop_btn=None,
129
  examples=[
130
- ["Hello there! How are you doing?"],
131
- ["Can you explain briefly to me what is the Python programming language?"],
132
- ["Explain the plot of Cinderella in a sentence."],
133
- ["How many hours does it take a man to eat a Helicopter?"],
134
- ["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
135
  ],
136
  )
137
 
138
  with gr.Blocks(css="style.css") as demo:
139
  gr.Markdown(DESCRIPTION)
140
- gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
141
  chat_interface.render()
142
- gr.Markdown(LICENSE)
143
 
144
  if __name__ == "__main__":
145
- demo.queue(max_size=20).launch(share=True, debug=True)
 
 
 
1
+ # Original code from https://huggingface.co/spaces/huggingface-projects/llama-2-13b-chat
2
+ # Modified for trust game purposes
3
  import os
4
  from threading import Thread
5
  from typing import Iterator
 
14
  MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
15
 
16
  DESCRIPTION = """\
17
+ # Llama-2 13B Chat
18
+ This is your personal space to chat.
19
+ You can ask anything from strategic questions regarding the game or just chat as you like.
 
 
 
 
20
  """
21
 
22
+ '''LICENSE = """
23
  <p/>
24
 
25
  ---
26
+ As a derivate work of [Llama-2-13b-chat](https://huggingface.co/meta-llama/Llama-2-13b-chat) by Meta,
27
+ this demo is governed by the original [license](https://huggingface.co/spaces/huggingface-projects/llama-2-13b-chat/blob/main/LICENSE.txt) and [acceptable use policy](https://huggingface.co/spaces/huggingface-projects/llama-2-13b-chat/blob/main/USE_POLICY.md).
28
  """
29
 
30
  if not torch.cuda.is_available():
31
  DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
32
 
33
 
34
+ if torch.cuda.is_available():
35
+ model_id = "meta-llama/Llama-2-13b-chat-hf"
36
+ model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", load_in_4bit=True)
37
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
38
+ tokenizer.use_default_system_prompt = False
39
+ '''
40
+
41
+
42
+ #if not torch.cuda.is_available():
43
+ # DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
44
+
45
+
46
  if torch.cuda.is_available():
47
  model_id = "meta-llama/Llama-2-7b-chat-hf"
48
  model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
49
  tokenizer = AutoTokenizer.from_pretrained(model_id)
50
  tokenizer.use_default_system_prompt = False
51
 
 
52
  @spaces.GPU
53
  def generate(
54
  message: str,
 
96
 
97
  chat_interface = gr.ChatInterface(
98
  fn=generate,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  examples=[
100
+ ["How much should I invest in order to win?"],
101
+ ["What happened in the last round?"],
102
+ ["What is my probability to win if I do not invest anything?"],
103
+ ["What is my probability to win if I do not share anything?"],
104
+ ["Can you explain the rules very briefly again?"],
105
  ],
106
  )
107
 
108
  with gr.Blocks(css="style.css") as demo:
109
  gr.Markdown(DESCRIPTION)
110
+ #gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
111
  chat_interface.render()
112
+ #gr.Markdown(LICENSE)
113
 
114
  if __name__ == "__main__":
115
+ #demo.queue(max_size=20).launch()
116
+ demo.queue(max_size=20)
117
+ demo.launch(share=True, debug=True)