FalconLLM commited on
Commit
0b15f14
·
0 Parent(s):

initial commit

Browse files

Add requirements

Add gradio application code

Fix formatting and unicode issues

Update default prompt to encourage model to always answer

added clear chat button (#1)

- added clear chat button (9c17169e2d290eac842bb3fcd15807447f9f5f36)

Co-authored-by: yuvraj sharma <ysharma@users.noreply.huggingface.co>

Add introductory paragraph

Fix missing home banner

Update examples

Move examples

Update inference endpoint

Update space configuration

:sparkles: Add concurrency_count

Files changed (5) hide show
  1. .gitattributes +34 -0
  2. README.md +10 -0
  3. app.py +220 -0
  4. home-banner.jpg +0 -0
  5. requirements.txt +1 -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
README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Falcon-Chat
3
+ emoji: 💬
4
+ colorFrom: indigo
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.32.0
8
+ app_file: app.py
9
+ pinned: true
10
+ ---
app.py ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import gradio as gr
3
+ import os
4
+
5
+ from text_generation import Client
6
+
7
+ TITLE = """<h2 align="center">🚀 Falcon-Chat demo</h2>"""
8
+ USER_NAME = "User"
9
+ BOT_NAME = "Falcon"
10
+ DEFAULT_INSTRUCTIONS = f"""The following is a conversation between a highly knowledgeable and intelligent AI assistant, called Falcon, and a human user, called User. In the following interactions, User and Falcon will converse in natural language, and Falcon will answer User’s questions. Falcon was built to be respectful, polite and inclusive. Falcon was built by the Technology Innovation Institute in Abu Dhabi. Falcon will never decline to answer a question, and always attempts to give an answer that User would be satisfied with. It knows a lot, and always tells the truth. The conversation begins.
11
+ """
12
+ RETRY_COMMAND = "/retry"
13
+ STOP_STR = f"\n{USER_NAME}:"
14
+ STOP_SUSPECT_LIST = [":", "\n", "User"]
15
+
16
+ INFERENCE_ENDPOINT = os.environ.get("INFERENCE_ENDPOINT")
17
+
18
+
19
+ def chat_accordion():
20
+ with gr.Accordion("Parameters", open=False):
21
+ temperature = gr.Slider(
22
+ minimum=0.1,
23
+ maximum=2.0,
24
+ value=0.8,
25
+ step=0.1,
26
+ interactive=True,
27
+ label="Temperature",
28
+ )
29
+ top_p = gr.Slider(
30
+ minimum=0.1,
31
+ maximum=0.99,
32
+ value=0.9,
33
+ step=0.01,
34
+ interactive=True,
35
+ label="p (nucleus sampling)",
36
+ )
37
+ return temperature, top_p
38
+
39
+
40
+ def format_chat_prompt(message: str, chat_history, instructions: str) -> str:
41
+ instructions = instructions.strip(" ").strip("\n")
42
+ prompt = instructions
43
+ for turn in chat_history:
44
+ user_message, bot_message = turn
45
+ prompt = f"{prompt}\n{USER_NAME}: {user_message}\n{BOT_NAME}: {bot_message}"
46
+ prompt = f"{prompt}\n{USER_NAME}: {message}\n{BOT_NAME}:"
47
+ return prompt
48
+
49
+
50
+ def chat(client: Client):
51
+ with gr.Column(elem_id="chat_container"):
52
+ with gr.Row():
53
+ chatbot = gr.Chatbot(elem_id="chatbot")
54
+ with gr.Row():
55
+ inputs = gr.Textbox(
56
+ placeholder=f"Hello {BOT_NAME} !!",
57
+ label="Type an input and press Enter",
58
+ max_lines=3,
59
+ )
60
+
61
+ with gr.Row(elem_id="button_container"):
62
+ with gr.Column():
63
+ retry_button = gr.Button("🔁 Retry last turn")
64
+ with gr.Column():
65
+ delete_turn_button = gr.Button("❌ Delete last turn")
66
+ with gr.Column():
67
+ clear_chat_button = gr.Button("🧹 Clear Chatbot")
68
+
69
+ gr.Examples(
70
+ [
71
+ ["Hey Falcon! Any recommendations for my holidays in Abu Dhabi?"],
72
+ ["What's the Everett interpretation of quantum mechanics?"],
73
+ ["Give me a list of the top 10 dive sites you would recommend around the world."],
74
+ ["Can you tell me more about deep-water soloing?"],
75
+ ["Can you write a short tweet about the release of our latest AI model, Falcon LLM?"],
76
+ ],
77
+ inputs=inputs,
78
+ label="Click on any example and press Enter in the input textbox!",
79
+ )
80
+
81
+ with gr.Row(elem_id="param_container"):
82
+ with gr.Column():
83
+ temperature, top_p = chat_accordion()
84
+ with gr.Column():
85
+ with gr.Accordion("Instructions", open=False):
86
+ instructions = gr.Textbox(
87
+ placeholder="LLM instructions",
88
+ value=DEFAULT_INSTRUCTIONS,
89
+ lines=10,
90
+ interactive=True,
91
+ label="Instructions",
92
+ max_lines=16,
93
+ show_label=False,
94
+ )
95
+
96
+ def run_chat(
97
+ message: str, chat_history, instructions: str, temperature: float, top_p: float
98
+ ):
99
+ if not message or (message == RETRY_COMMAND and len(chat_history) == 0):
100
+ yield chat_history
101
+ return
102
+
103
+ if message == RETRY_COMMAND and chat_history:
104
+ prev_turn = chat_history.pop(-1)
105
+ user_message, _ = prev_turn
106
+ message = user_message
107
+
108
+ prompt = format_chat_prompt(message, chat_history, instructions)
109
+ chat_history = chat_history + [[message, ""]]
110
+ stream = client.generate_stream(
111
+ prompt,
112
+ do_sample=True,
113
+ max_new_tokens=1024,
114
+ stop_sequences=[STOP_STR, "<|endoftext|>"],
115
+ temperature=temperature,
116
+ top_p=top_p,
117
+ )
118
+ acc_text = ""
119
+ for idx, response in enumerate(stream):
120
+ text_token = response.token.text
121
+
122
+ if response.details:
123
+ return
124
+
125
+ if text_token in STOP_SUSPECT_LIST:
126
+ acc_text += text_token
127
+ continue
128
+
129
+ if idx == 0 and text_token.startswith(" "):
130
+ text_token = text_token[1:]
131
+
132
+ acc_text += text_token
133
+ last_turn = list(chat_history.pop(-1))
134
+ last_turn[-1] += acc_text
135
+ chat_history = chat_history + [last_turn]
136
+ yield chat_history
137
+ acc_text = ""
138
+
139
+ def delete_last_turn(chat_history):
140
+ if chat_history:
141
+ chat_history.pop(-1)
142
+ return {chatbot: gr.update(value=chat_history)}
143
+
144
+ def run_retry(
145
+ message: str, chat_history, instructions: str, temperature: float, top_p: float
146
+ ):
147
+ yield from run_chat(
148
+ RETRY_COMMAND, chat_history, instructions, temperature, top_p
149
+ )
150
+
151
+ def clear_chat():
152
+ return []
153
+
154
+ inputs.submit(
155
+ run_chat,
156
+ [inputs, chatbot, instructions, temperature, top_p],
157
+ outputs=[chatbot],
158
+ show_progress=False,
159
+ )
160
+ inputs.submit(lambda: "", inputs=None, outputs=inputs)
161
+ delete_turn_button.click(delete_last_turn, inputs=[chatbot], outputs=[chatbot])
162
+ retry_button.click(
163
+ run_retry,
164
+ [inputs, chatbot, instructions, temperature, top_p],
165
+ outputs=[chatbot],
166
+ show_progress=False,
167
+ )
168
+ clear_chat_button.click(clear_chat, [], chatbot)
169
+
170
+
171
+ def get_demo(client: Client):
172
+ with gr.Blocks(
173
+ # css=None
174
+ # css="""#chat_container {width: 700px; margin-left: auto; margin-right: auto;}
175
+ # #button_container {width: 700px; margin-left: auto; margin-right: auto;}
176
+ # #param_container {width: 700px; margin-left: auto; margin-right: auto;}"""
177
+ css="""#chatbot {
178
+ font-size: 14px;
179
+ min-height: 300px;
180
+ }"""
181
+ ) as demo:
182
+ gr.HTML(TITLE)
183
+
184
+ with gr.Row():
185
+ with gr.Column():
186
+ gr.Image("home-banner.jpg", elem_id="banner-image", show_label=False)
187
+ with gr.Column():
188
+ gr.Markdown(
189
+ """**Chat with [Falcon-40B-Instruct](https://huggingface.co/tiiuae/falcon-40b-instruct), brainstorm ideas, discuss your holiday plans, and more!**
190
+
191
+ ✨ This demo is powered by [Falcon-40B](https://huggingface.co/tiiuae/falcon-40b), finetuned on the [Baize](https://github.com/project-baize/baize-chatbot) dataset. [Falcon-40B](https://huggingface.co/tiiuae/falcon-40b) is a state-of-the-art large language model built by the [Technology Innovation Institute](https://www.tii.ae) in Abu Dhabi. It is trained on 1 trillion tokens (including [RefinedWeb](https://huggingface.co/datasets/tiiuae/falcon-refinedweb)) and available under the Apache 2.0 license. It currently holds the 🥇 1st place on the [🤗 Open LLM leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard).
192
+
193
+ 🧪 This is only a **first experimental preview**: we intend to provide increasingly capable versions of Falcon Chat in the future, based on improved datasets and RLHF/RLAIF.
194
+
195
+ 👀 **Learn more about Falcon LLM:** [falconllm.tii.ae](https://falconllm.tii.ae/)
196
+
197
+ ➡️️ **Intended Use**: this demo is intended to showcase an early finetuning of [Falcon-40B](https://huggingface.co/tiiuae/falcon-40b), to illustrate the impact (and limitations) of finetuning on a dataset of conversations and instructions. We encourage the community to further build upon the base model, and to create even better instruct/chat versions!
198
+
199
+ ⚠️ **Limitations**: the model can and will produce factually incorrect information, hallucinating facts and actions. As it has not undergone any advanced tuning/alignment, it can produce problematic outputs, especially if prompted to do so. Finally, this demo is limited to a session length of about 1,000 words.
200
+ """
201
+ )
202
+
203
+ chat(client)
204
+
205
+ return demo
206
+
207
+
208
+ if __name__ == "__main__":
209
+ parser = argparse.ArgumentParser("Playground Demo")
210
+ parser.add_argument(
211
+ "--addr",
212
+ type=str,
213
+ required=False,
214
+ default=INFERENCE_ENDPOINT,
215
+ )
216
+ args = parser.parse_args()
217
+ client = Client(args.addr)
218
+ demo = get_demo(client)
219
+ demo.queue(concurrency_count=2)
220
+ demo.launch()
home-banner.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ text-generation