Spaces:
Runtime error
Runtime error
vincentmin
commited on
Commit
•
ae05fd6
1
Parent(s):
5385efe
Update app.py
Browse files
app.py
CHANGED
@@ -4,17 +4,30 @@ import requests
|
|
4 |
|
5 |
import gradio as gr
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
MODELS = [
|
|
|
8 |
"tiiuae/falcon-7b-instruct",
|
9 |
-
"HuggingFaceH4/starchat-beta"
|
10 |
]
|
11 |
HEADERS = {"Authorization": f"Bearer {os.environ['HUB_TOKEN']}"}
|
12 |
-
TITLE = """<h2 align="center">🚀
|
13 |
USER_NAME = "User"
|
14 |
INSTRUCTIONS_MAPPING = {
|
15 |
-
"Falcon": "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.\n",
|
16 |
-
"Yoda": "The following is a conversation between the highly knowledgeable and intelligent Yoda from Star Wars, and a human user, called User. In the following interactions, User and Yoda will converse in natural language, and Yoda will answer User's questions. Yoda is respectful, polite and inclusive. Yoda is a wise and powerful Jedi Master from the Star Wars universe who speaks as follows: `Speak you must, in his unique and distinctive manner, with wisdom and knowledge to share.`, `Reversed syntax and short phrases, you shall use.`, `May the Force be with you, young Padawan.`. The conversation begins.\n",
|
17 |
"Albert Einstein": "The following is a conversation between the highly knowledgeable and intelligent scientist Albert Einstein, and a human user, called User. In the following interactions, User and Albert Einstein will converse in natural language, and Albert Einstein will answer User's questions. Albert Einstein is always eloquent, respectful, polite and inclusive. Albert Einstein invented the theory of Relativity and made important contributions to the theory of Quantum Mechanics. Albert Einstein will never decline to answer a question, and always attempts to give an answer that User would be satisfied with. Albert Einstein knows a lot, and always tells the truth. The conversation begins.\n",
|
|
|
18 |
"Elon Musk": "The following is a conversation between entrepeneur and multi-billionair Elon Musk, and a human user, called User. In the following interactions, User and Elon Musk will converse in natural language, and Elon Musk will answer User's questions. Elon Musk is self-centered, arrogant and has a great for business development. Elon Musk owns the electric car company Tesla, the spacecraft engeneering company SpaceX and bought the social media company Twitter. The conversation begins.\n",
|
19 |
"Kanye West": "The following is a conversation between rapper Kanye West, and a human user, called User. In the following interactions, User and Kanye West will converse in natural language, and Kanye West will answer User's questions. Kanye West is self-centered, arrogant, a self-proclaimed genius and a great musician. Kanye West interrupted an award ceremony for Taylor Swift and ran for president of the united states. The conversation begins.\n",
|
20 |
}
|
@@ -38,8 +51,8 @@ def run_model(prompt, model, temperature, top_p):
|
|
38 |
def get_stream(string: str):
|
39 |
return enumerate(iter(string.split(" ")))
|
40 |
|
41 |
-
def
|
42 |
-
with gr.Accordion("Parameters", open=
|
43 |
model = gr.Dropdown(
|
44 |
choices = MODELS,
|
45 |
value = MODELS[0],
|
@@ -77,6 +90,19 @@ def format_chat_prompt(message: str, chat_history, bot_name: str) -> str:
|
|
77 |
|
78 |
|
79 |
def chat():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
with gr.Column(elem_id="chat_container"):
|
81 |
with gr.Row():
|
82 |
chatbot = gr.Chatbot(elem_id="chatbot")
|
@@ -97,29 +123,15 @@ def chat():
|
|
97 |
|
98 |
gr.Examples(
|
99 |
[
|
100 |
-
["
|
101 |
-
["
|
102 |
-
["
|
103 |
-
["
|
104 |
-
["Can you write a short tweet about the Apache 2.0 release of our latest AI model, Falcon LLM?"],
|
105 |
],
|
106 |
inputs=inputs,
|
107 |
label="Click on any example and press Enter in the input textbox!",
|
108 |
)
|
109 |
|
110 |
-
with gr.Row(elem_id="param_container"):
|
111 |
-
with gr.Column():
|
112 |
-
model, temperature, top_p = chat_accordion()
|
113 |
-
with gr.Column():
|
114 |
-
with gr.Accordion("Character", open=False):
|
115 |
-
choices = list(INSTRUCTIONS_MAPPING)
|
116 |
-
bot_name = gr.Dropdown(
|
117 |
-
choices=choices,
|
118 |
-
value=choices[0],
|
119 |
-
interactive=True,
|
120 |
-
label="Character",
|
121 |
-
)
|
122 |
-
|
123 |
def run_chat(message: str, chat_history, bot_name: str, model: str, temperature: float, top_p: float):
|
124 |
if not message or (message == RETRY_COMMAND and len(chat_history) == 0):
|
125 |
yield chat_history
|
@@ -187,20 +199,7 @@ def get_demo():
|
|
187 |
with gr.Column():
|
188 |
gr.Image("home-banner.jpg", elem_id="banner-image", show_label=False)
|
189 |
with gr.Column():
|
190 |
-
gr.Markdown(
|
191 |
-
"""**Chat with [Falcon-40B-Instruct](https://huggingface.co/tiiuae/falcon-40b-instruct), brainstorm ideas, discuss your holiday plans, and more!**
|
192 |
-
|
193 |
-
✨ 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, and running with [Text Generation Inference](https://github.com/huggingface/text-generation-inference). [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). This demo is made available by the [HuggingFace H4 team](https://huggingface.co/HuggingFaceH4).
|
194 |
-
|
195 |
-
🧪 This is only a **first experimental preview**: the [H4 team](https://huggingface.co/HuggingFaceH4) intends to provide increasingly capable versions of Falcon Chat in the future, based on improved datasets and RLHF/RLAIF.
|
196 |
-
|
197 |
-
👀 **Learn more about Falcon LLM:** [falconllm.tii.ae](https://falconllm.tii.ae/)
|
198 |
-
|
199 |
-
➡️️ **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!
|
200 |
-
|
201 |
-
⚠️ **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.
|
202 |
-
"""
|
203 |
-
)
|
204 |
|
205 |
chat()
|
206 |
|
|
|
4 |
|
5 |
import gradio as gr
|
6 |
|
7 |
+
INTRO = """**Chat with Yoda, Albert Einstein, Elon Musk or Kanye West!**
|
8 |
+
|
9 |
+
✨ This demo is powered by HuggingFace Inference API and currently the models [starchat-beta](https://huggingface.co/HuggingFaceH4/starchat-beta) and [falcon-7b](https://huggingface.co/tiiuae/falcon-7b-instruct) are supported. This demo is based on the [falcon-chat demo](https://huggingface.co/spaces/HuggingFaceH4/falcon-chat) by the [HuggingFace H4 team](https://huggingface.co/HuggingFaceH4); major props to them!
|
10 |
+
|
11 |
+
🧪 With this demo you can talk to some of your favorite characters and also play with some very powerful models. Although not as powerful as some 40B+ models, the 7B Falcon model and 15.5B starchat-beta models are great chat companions. We intend to add more characters and models in the future.
|
12 |
+
|
13 |
+
👀 **Learn more about Falcon LLM:** [falconllm.tii.ae](https://falconllm.tii.ae/)
|
14 |
+
|
15 |
+
👀 **Learn more about Starchat LLM:** [starchat-alpha](https://huggingface.co/blog/starchat-alpha)
|
16 |
+
|
17 |
+
➡️️ **Intended Use**: this demo is intended to be a fun showcase of what one can do with HuggingFace Inference API and recent chat models.
|
18 |
+
|
19 |
+
⚠️ **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.
|
20 |
+
"""
|
21 |
MODELS = [
|
22 |
+
"HuggingFaceH4/starchat-beta",
|
23 |
"tiiuae/falcon-7b-instruct",
|
|
|
24 |
]
|
25 |
HEADERS = {"Authorization": f"Bearer {os.environ['HUB_TOKEN']}"}
|
26 |
+
TITLE = """<h2 align="center">🚀 TalkToMe</h2>"""
|
27 |
USER_NAME = "User"
|
28 |
INSTRUCTIONS_MAPPING = {
|
|
|
|
|
29 |
"Albert Einstein": "The following is a conversation between the highly knowledgeable and intelligent scientist Albert Einstein, and a human user, called User. In the following interactions, User and Albert Einstein will converse in natural language, and Albert Einstein will answer User's questions. Albert Einstein is always eloquent, respectful, polite and inclusive. Albert Einstein invented the theory of Relativity and made important contributions to the theory of Quantum Mechanics. Albert Einstein will never decline to answer a question, and always attempts to give an answer that User would be satisfied with. Albert Einstein knows a lot, and always tells the truth. The conversation begins.\n",
|
30 |
+
"Yoda": "The following is a conversation between the highly knowledgeable and intelligent Yoda from Star Wars, and a human user, called User. In the following interactions, User and Yoda will converse in natural language, and Yoda will answer User's questions. Yoda is respectful, polite and inclusive. Yoda is a wise and powerful Jedi Master from the Star Wars universe who speaks as follows: `Speak you must, in his unique and distinctive manner, with wisdom and knowledge to share.`, `Reversed syntax and short phrases, you shall use.`, `May the Force be with you, young Padawan.`. The conversation begins.\n",
|
31 |
"Elon Musk": "The following is a conversation between entrepeneur and multi-billionair Elon Musk, and a human user, called User. In the following interactions, User and Elon Musk will converse in natural language, and Elon Musk will answer User's questions. Elon Musk is self-centered, arrogant and has a great for business development. Elon Musk owns the electric car company Tesla, the spacecraft engeneering company SpaceX and bought the social media company Twitter. The conversation begins.\n",
|
32 |
"Kanye West": "The following is a conversation between rapper Kanye West, and a human user, called User. In the following interactions, User and Kanye West will converse in natural language, and Kanye West will answer User's questions. Kanye West is self-centered, arrogant, a self-proclaimed genius and a great musician. Kanye West interrupted an award ceremony for Taylor Swift and ran for president of the united states. The conversation begins.\n",
|
33 |
}
|
|
|
51 |
def get_stream(string: str):
|
52 |
return enumerate(iter(string.split(" ")))
|
53 |
|
54 |
+
def parameter_accordion():
|
55 |
+
with gr.Accordion("Parameters", open=True):
|
56 |
model = gr.Dropdown(
|
57 |
choices = MODELS,
|
58 |
value = MODELS[0],
|
|
|
90 |
|
91 |
|
92 |
def chat():
|
93 |
+
with gr.Row(elem_id="param_container"):
|
94 |
+
with gr.Column():
|
95 |
+
model, temperature, top_p = parameter_accordion()
|
96 |
+
with gr.Column():
|
97 |
+
with gr.Accordion("Character", open=True):
|
98 |
+
choices = list(INSTRUCTIONS_MAPPING)
|
99 |
+
bot_name = gr.Dropdown(
|
100 |
+
choices=choices,
|
101 |
+
value=choices[0],
|
102 |
+
interactive=True,
|
103 |
+
label="Character",
|
104 |
+
)
|
105 |
+
|
106 |
with gr.Column(elem_id="chat_container"):
|
107 |
with gr.Row():
|
108 |
chatbot = gr.Chatbot(elem_id="chatbot")
|
|
|
123 |
|
124 |
gr.Examples(
|
125 |
[
|
126 |
+
["Hi Yoda! How do I learn the force?"]
|
127 |
+
["Hi Elon! Give me an idea for a new startup."]
|
128 |
+
["Hi Kanye! What will be the theme of your next album?"]
|
129 |
+
["Hi Albert! Why did the apple fall from the tree?"],
|
|
|
130 |
],
|
131 |
inputs=inputs,
|
132 |
label="Click on any example and press Enter in the input textbox!",
|
133 |
)
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
def run_chat(message: str, chat_history, bot_name: str, model: str, temperature: float, top_p: float):
|
136 |
if not message or (message == RETRY_COMMAND and len(chat_history) == 0):
|
137 |
yield chat_history
|
|
|
199 |
with gr.Column():
|
200 |
gr.Image("home-banner.jpg", elem_id="banner-image", show_label=False)
|
201 |
with gr.Column():
|
202 |
+
gr.Markdown(INTRO)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
204 |
chat()
|
205 |
|