Spaces:
No application file
No application file
Commit
·
50ac637
1
Parent(s):
23269a4
Rename app.py to app.js
Browse files
app.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
async function query(data) {
|
| 2 |
+
const response = await fetch(
|
| 3 |
+
"https://api-inference.huggingface.co/models/OpenAssistant/oasst-sft-1-pythia-12b",
|
| 4 |
+
{
|
| 5 |
+
headers: { Authorization: "Bearer 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" },
|
| 6 |
+
method: "POST",
|
app.py
DELETED
|
@@ -1,305 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
|
| 3 |
-
import gradio as gr
|
| 4 |
-
|
| 5 |
-
gr.Interface.load("models/OpenAssistant/oasst-sft-1-pythia-12b").launch()
|
| 6 |
-
|
| 7 |
-
openchat_preprompt = (
|
| 8 |
-
"\n<human>: Hi!\n<bot>: My name is multivac, model version is 0.15, part of an open-source kit for "
|
| 9 |
-
"fine-tuning new bots! I was created by Together, LAION, and Ontocord.ai and the open-source "
|
| 10 |
-
"community. I am not human, not evil and not alive, and thus have no thoughts and feelings, "
|
| 11 |
-
"but I am programmed to be helpful, polite, honest, and friendly.\n"
|
| 12 |
-
)
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def get_usernames(model: str):
|
| 17 |
-
"""
|
| 18 |
-
Returns:
|
| 19 |
-
(str, str, str, str): pre-prompt, username, bot name, separator
|
| 20 |
-
"""
|
| 21 |
-
if model == "OpenAssistant/oasst-sft-1-pythia-12b":
|
| 22 |
-
return "", "<|prompter|>", "<|assistant|>", "<|endoftext|>"
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
def predict(
|
| 27 |
-
model: str,
|
| 28 |
-
inputs: str,
|
| 29 |
-
typical_p: float,
|
| 30 |
-
top_p: float,
|
| 31 |
-
temperature: float,
|
| 32 |
-
top_k: int,
|
| 33 |
-
repetition_penalty: float,
|
| 34 |
-
watermark: bool,
|
| 35 |
-
chatbot,
|
| 36 |
-
history,
|
| 37 |
-
):
|
| 38 |
-
client = get_client(openchat_preprompt)
|
| 39 |
-
preprompt, user_name, assistant_name, sep = get_usernames(model)
|
| 40 |
-
|
| 41 |
-
history.append(inputs)
|
| 42 |
-
|
| 43 |
-
past = []
|
| 44 |
-
for data in chatbot:
|
| 45 |
-
user_data, model_data = data
|
| 46 |
-
|
| 47 |
-
if not user_data.startswith(user_name):
|
| 48 |
-
user_data = user_name + user_data
|
| 49 |
-
if not model_data.startswith(sep + assistant_name):
|
| 50 |
-
model_data = sep + assistant_name + model_data
|
| 51 |
-
|
| 52 |
-
past.append(user_data + model_data.rstrip() + sep)
|
| 53 |
-
|
| 54 |
-
if not inputs.startswith(user_name):
|
| 55 |
-
inputs = user_name + inputs
|
| 56 |
-
|
| 57 |
-
total_inputs = preprompt + "".join(past) + inputs + sep + assistant_name.rstrip()
|
| 58 |
-
|
| 59 |
-
partial_words = ""
|
| 60 |
-
|
| 61 |
-
if model == "OpenAssistant/oasst-sft-1-pythia-12b":
|
| 62 |
-
iterator = client.generate_stream(
|
| 63 |
-
total_inputs,
|
| 64 |
-
typical_p=typical_p,
|
| 65 |
-
truncate=1000,
|
| 66 |
-
watermark=watermark,
|
| 67 |
-
max_new_tokens=500,
|
| 68 |
-
)
|
| 69 |
-
else:
|
| 70 |
-
iterator = client.generate_stream(
|
| 71 |
-
total_inputs,
|
| 72 |
-
top_p=top_p if top_p < 1.0 else None,
|
| 73 |
-
top_k=top_k,
|
| 74 |
-
truncate=1000,
|
| 75 |
-
repetition_penalty=repetition_penalty,
|
| 76 |
-
watermark=watermark,
|
| 77 |
-
temperature=temperature,
|
| 78 |
-
max_new_tokens=500,
|
| 79 |
-
stop_sequences=[user_name.rstrip(), assistant_name.rstrip()],
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
for i, response in enumerate(iterator):
|
| 83 |
-
if response.token.special:
|
| 84 |
-
continue
|
| 85 |
-
|
| 86 |
-
partial_words = partial_words + response.token.text
|
| 87 |
-
if partial_words.endswith(user_name.rstrip()):
|
| 88 |
-
partial_words = partial_words.rstrip(user_name.rstrip())
|
| 89 |
-
if partial_words.endswith(assistant_name.rstrip()):
|
| 90 |
-
partial_words = partial_words.rstrip(assistant_name.rstrip())
|
| 91 |
-
|
| 92 |
-
if i == 0:
|
| 93 |
-
history.append(" " + partial_words)
|
| 94 |
-
elif response.token.text not in user_name:
|
| 95 |
-
history[-1] = partial_words
|
| 96 |
-
|
| 97 |
-
chat = [
|
| 98 |
-
(history[i].strip(), history[i + 1].strip())
|
| 99 |
-
for i in range(0, len(history) - 1, 2)
|
| 100 |
-
]
|
| 101 |
-
yield chat, history
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
def reset_textbox():
|
| 105 |
-
return gr.update(value="")
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
def radio_on_change(
|
| 109 |
-
value: str,
|
| 110 |
-
disclaimer,
|
| 111 |
-
typical_p,
|
| 112 |
-
top_p,
|
| 113 |
-
top_k,
|
| 114 |
-
temperature,
|
| 115 |
-
repetition_penalty,
|
| 116 |
-
watermark,
|
| 117 |
-
):
|
| 118 |
-
if value == "OpenAssistant/oasst-sft-1-pythia-12b":
|
| 119 |
-
typical_p = typical_p.update(value=0.2, visible=True)
|
| 120 |
-
top_p = top_p.update(visible=False)
|
| 121 |
-
top_k = top_k.update(visible=False)
|
| 122 |
-
temperature = temperature.update(visible=False)
|
| 123 |
-
disclaimer = disclaimer.update(visible=False)
|
| 124 |
-
repetition_penalty = repetition_penalty.update(visible=False)
|
| 125 |
-
watermark = watermark.update(False)
|
| 126 |
-
elif value == "togethercomputer/GPT-NeoXT-Chat-Base-20B":
|
| 127 |
-
typical_p = typical_p.update(visible=False)
|
| 128 |
-
top_p = top_p.update(value=0.25, visible=True)
|
| 129 |
-
top_k = top_k.update(value=50, visible=True)
|
| 130 |
-
temperature = temperature.update(value=0.6, visible=True)
|
| 131 |
-
repetition_penalty = repetition_penalty.update(value=1.01, visible=True)
|
| 132 |
-
watermark = watermark.update(False)
|
| 133 |
-
disclaimer = disclaimer.update(visible=True)
|
| 134 |
-
else:
|
| 135 |
-
typical_p = typical_p.update(visible=False)
|
| 136 |
-
top_p = top_p.update(value=0.95, visible=True)
|
| 137 |
-
top_k = top_k.update(value=4, visible=True)
|
| 138 |
-
temperature = temperature.update(value=0.5, visible=True)
|
| 139 |
-
repetition_penalty = repetition_penalty.update(value=1.03, visible=True)
|
| 140 |
-
watermark = watermark.update(True)
|
| 141 |
-
disclaimer = disclaimer.update(visible=False)
|
| 142 |
-
return (
|
| 143 |
-
disclaimer,
|
| 144 |
-
typical_p,
|
| 145 |
-
top_p,
|
| 146 |
-
top_k,
|
| 147 |
-
temperature,
|
| 148 |
-
repetition_penalty,
|
| 149 |
-
watermark,
|
| 150 |
-
)
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
title = """<h1 align="center">🔥SAPIENS-IA🚀</h1>"""
|
| 154 |
-
description = """Language models can be conditioned to act like dialogue agents through a conversational prompt that typically takes the form:
|
| 155 |
-
```
|
| 156 |
-
User: <utterance>
|
| 157 |
-
Assistant: <utterance>
|
| 158 |
-
User: <utterance>
|
| 159 |
-
Assistant: <utterance>
|
| 160 |
-
...
|
| 161 |
-
```
|
| 162 |
-
In this app, you can explore the outputs of multiple LLMs when prompted in this way.
|
| 163 |
-
"""
|
| 164 |
-
|
| 165 |
-
openchat_disclaimer = """
|
| 166 |
-
<div align="center">Checkout the official <a href=https://huggingface.co/spaces/togethercomputer/OpenChatKit>OpenChatKit feedback app</a> for the full experience.</div>
|
| 167 |
-
"""
|
| 168 |
-
|
| 169 |
-
with gr.Blocks(
|
| 170 |
-
css="""#col_container {margin-left: auto; margin-right: auto;}
|
| 171 |
-
#chatbot {height: 520px; overflow: auto;}"""
|
| 172 |
-
) as demo:
|
| 173 |
-
gr.HTML(title)
|
| 174 |
-
with gr.Column(elem_id="col_container"):
|
| 175 |
-
model = gr.Radio(
|
| 176 |
-
value="OpenAssistant/oasst-sft-1-pythia-12b",
|
| 177 |
-
choices=[
|
| 178 |
-
"OpenAssistant/oasst-sft-1-pythia-12b",
|
| 179 |
-
# "togethercomputer/GPT-NeoXT-Chat-Base-20B",
|
| 180 |
-
"Rallio67/joi2_20Be_instruct_alpha",
|
| 181 |
-
"google/flan-t5-xxl",
|
| 182 |
-
"google/flan-ul2",
|
| 183 |
-
"bigscience/bloom",
|
| 184 |
-
"bigscience/bloomz",
|
| 185 |
-
"EleutherAI/gpt-neox-20b",
|
| 186 |
-
],
|
| 187 |
-
label="Model",
|
| 188 |
-
interactive=True,
|
| 189 |
-
)
|
| 190 |
-
|
| 191 |
-
chatbot = gr.Chatbot(elem_id="chatbot")
|
| 192 |
-
inputs = gr.Textbox(
|
| 193 |
-
placeholder="Hi there!", label="Type an input and press Enter"
|
| 194 |
-
)
|
| 195 |
-
disclaimer = gr.Markdown(openchat_disclaimer, visible=False)
|
| 196 |
-
state = gr.State([])
|
| 197 |
-
b1 = gr.Button()
|
| 198 |
-
|
| 199 |
-
with gr.Accordion("Parameters", open=False):
|
| 200 |
-
typical_p = gr.Slider(
|
| 201 |
-
minimum=-0,
|
| 202 |
-
maximum=1.0,
|
| 203 |
-
value=0.2,
|
| 204 |
-
step=0.05,
|
| 205 |
-
interactive=True,
|
| 206 |
-
label="Typical P mass",
|
| 207 |
-
)
|
| 208 |
-
top_p = gr.Slider(
|
| 209 |
-
minimum=-0,
|
| 210 |
-
maximum=1.0,
|
| 211 |
-
value=0.25,
|
| 212 |
-
step=0.05,
|
| 213 |
-
interactive=True,
|
| 214 |
-
label="Top-p (nucleus sampling)",
|
| 215 |
-
visible=False,
|
| 216 |
-
)
|
| 217 |
-
temperature = gr.Slider(
|
| 218 |
-
minimum=-0,
|
| 219 |
-
maximum=5.0,
|
| 220 |
-
value=0.6,
|
| 221 |
-
step=0.1,
|
| 222 |
-
interactive=True,
|
| 223 |
-
label="Temperature",
|
| 224 |
-
visible=False,
|
| 225 |
-
)
|
| 226 |
-
top_k = gr.Slider(
|
| 227 |
-
minimum=1,
|
| 228 |
-
maximum=50,
|
| 229 |
-
value=50,
|
| 230 |
-
step=1,
|
| 231 |
-
interactive=True,
|
| 232 |
-
label="Top-k",
|
| 233 |
-
visible=False,
|
| 234 |
-
)
|
| 235 |
-
repetition_penalty = gr.Slider(
|
| 236 |
-
minimum=0.1,
|
| 237 |
-
maximum=3.0,
|
| 238 |
-
value=1.03,
|
| 239 |
-
step=0.01,
|
| 240 |
-
interactive=True,
|
| 241 |
-
label="Repetition Penalty",
|
| 242 |
-
visible=False,
|
| 243 |
-
)
|
| 244 |
-
watermark = gr.Checkbox(value=False, label="Text watermarking")
|
| 245 |
-
|
| 246 |
-
model.change(
|
| 247 |
-
lambda value: radio_on_change(
|
| 248 |
-
value,
|
| 249 |
-
disclaimer,
|
| 250 |
-
typical_p,
|
| 251 |
-
top_p,
|
| 252 |
-
top_k,
|
| 253 |
-
temperature,
|
| 254 |
-
repetition_penalty,
|
| 255 |
-
watermark,
|
| 256 |
-
),
|
| 257 |
-
inputs=model,
|
| 258 |
-
outputs=[
|
| 259 |
-
disclaimer,
|
| 260 |
-
typical_p,
|
| 261 |
-
top_p,
|
| 262 |
-
top_k,
|
| 263 |
-
temperature,
|
| 264 |
-
repetition_penalty,
|
| 265 |
-
watermark,
|
| 266 |
-
],
|
| 267 |
-
)
|
| 268 |
-
|
| 269 |
-
inputs.submit(
|
| 270 |
-
predict,
|
| 271 |
-
[
|
| 272 |
-
model,
|
| 273 |
-
inputs,
|
| 274 |
-
typical_p,
|
| 275 |
-
top_p,
|
| 276 |
-
temperature,
|
| 277 |
-
top_k,
|
| 278 |
-
repetition_penalty,
|
| 279 |
-
watermark,
|
| 280 |
-
chatbot,
|
| 281 |
-
state,
|
| 282 |
-
],
|
| 283 |
-
[chatbot, state],
|
| 284 |
-
)
|
| 285 |
-
b1.click(
|
| 286 |
-
predict,
|
| 287 |
-
[
|
| 288 |
-
model,
|
| 289 |
-
inputs,
|
| 290 |
-
typical_p,
|
| 291 |
-
top_p,
|
| 292 |
-
temperature,
|
| 293 |
-
top_k,
|
| 294 |
-
repetition_penalty,
|
| 295 |
-
watermark,
|
| 296 |
-
chatbot,
|
| 297 |
-
state,
|
| 298 |
-
],
|
| 299 |
-
[chatbot, state],
|
| 300 |
-
)
|
| 301 |
-
b1.click(reset_textbox, [], [inputs])
|
| 302 |
-
inputs.submit(reset_textbox, [], [inputs])
|
| 303 |
-
|
| 304 |
-
gr.Markdown(description)
|
| 305 |
-
demo.queue(concurrency_count=16).launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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