Spaces:
Runtime error
Runtime error
fixes
Browse files
app.py
CHANGED
|
@@ -18,6 +18,13 @@ BOT_TOKEN = 9225
|
|
| 18 |
LINEBREAK_TOKEN = 13
|
| 19 |
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def get_message_tokens(model, role, content):
|
| 22 |
message_tokens = model.tokenize(content.encode("utf-8"))
|
| 23 |
message_tokens.insert(1, ROLE_TOKENS[role])
|
|
@@ -67,8 +74,6 @@ def bot(
|
|
| 67 |
tokens.extend(message_tokens)
|
| 68 |
|
| 69 |
last_user_message = history[-1][0]
|
| 70 |
-
if retrieved_docs:
|
| 71 |
-
last_user_message = f"Контекст: {retrieved_docs}\n\nИспользуя контекст, ответь на вопрос: {last_user_message}"
|
| 72 |
message_tokens = get_message_tokens(model=model, role="user", content=last_user_message)
|
| 73 |
tokens.extend(message_tokens)
|
| 74 |
|
|
@@ -96,12 +101,12 @@ with gr.Blocks(
|
|
| 96 |
favicon = '<img src="https://cdn.midjourney.com/b88e5beb-6324-4820-8504-a1a37a9ba36d/0_1.png" width="48px" style="display: inline">'
|
| 97 |
gr.Markdown(
|
| 98 |
f"""<h1><center>{favicon}Saiga2 13B</center></h1>
|
| 99 |
-
|
| 100 |
This is a demo of a **Russian**-speaking LLaMA2-based model. If you are interested in other languages, please check other models, such as [MPT-7B-Chat](https://huggingface.co/spaces/mosaicml/mpt-7b-chat).
|
| 101 |
-
|
| 102 |
-
Это демонстрационная версия
|
| 103 |
-
|
| 104 |
-
|
| 105 |
"""
|
| 106 |
)
|
| 107 |
with gr.Row():
|
|
@@ -150,7 +155,7 @@ with gr.Blocks(
|
|
| 150 |
gr.Markdown(
|
| 151 |
"""ПРЕДУПРЕЖДЕНИЕ: Модель может генерировать фактически или этически некорректные тексты. Мы не несём за это ответственность."""
|
| 152 |
)
|
| 153 |
-
|
| 154 |
# Pressing Enter
|
| 155 |
submit_event = msg.submit(
|
| 156 |
fn=user,
|
|
@@ -202,4 +207,4 @@ with gr.Blocks(
|
|
| 202 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 203 |
|
| 204 |
demo.queue(max_size=128, concurrency_count=1)
|
| 205 |
-
demo.launch()
|
|
|
|
| 18 |
LINEBREAK_TOKEN = 13
|
| 19 |
|
| 20 |
|
| 21 |
+
ROLE_TOKENS = {
|
| 22 |
+
"user": USER_TOKEN,
|
| 23 |
+
"bot": BOT_TOKEN,
|
| 24 |
+
"system": SYSTEM_TOKEN
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
def get_message_tokens(model, role, content):
|
| 29 |
message_tokens = model.tokenize(content.encode("utf-8"))
|
| 30 |
message_tokens.insert(1, ROLE_TOKENS[role])
|
|
|
|
| 74 |
tokens.extend(message_tokens)
|
| 75 |
|
| 76 |
last_user_message = history[-1][0]
|
|
|
|
|
|
|
| 77 |
message_tokens = get_message_tokens(model=model, role="user", content=last_user_message)
|
| 78 |
tokens.extend(message_tokens)
|
| 79 |
|
|
|
|
| 101 |
favicon = '<img src="https://cdn.midjourney.com/b88e5beb-6324-4820-8504-a1a37a9ba36d/0_1.png" width="48px" style="display: inline">'
|
| 102 |
gr.Markdown(
|
| 103 |
f"""<h1><center>{favicon}Saiga2 13B</center></h1>
|
| 104 |
+
|
| 105 |
This is a demo of a **Russian**-speaking LLaMA2-based model. If you are interested in other languages, please check other models, such as [MPT-7B-Chat](https://huggingface.co/spaces/mosaicml/mpt-7b-chat).
|
| 106 |
+
|
| 107 |
+
Это демонстрационная версия [квантованной Сайги-2 с 13 миллиардами параметров](https://huggingface.co/IlyaGusev/saiga2_13b_ggml), работающая на CPU.
|
| 108 |
+
|
| 109 |
+
Сайга-2 — это разговорная языковая модель, которая основана на [LLaMA-2](https://ai.meta.com/llama/) и дообучена на корпусах, сгенерированных ChatGPT, таких как [ru_turbo_alpaca](https://huggingface.co/datasets/IlyaGusev/ru_turbo_alpaca), [ru_turbo_saiga](https://huggingface.co/datasets/IlyaGusev/ru_turbo_saiga) и [gpt_roleplay_realm](https://huggingface.co/datasets/IlyaGusev/gpt_roleplay_realm).
|
| 110 |
"""
|
| 111 |
)
|
| 112 |
with gr.Row():
|
|
|
|
| 155 |
gr.Markdown(
|
| 156 |
"""ПРЕДУПРЕЖДЕНИЕ: Модель может генерировать фактически или этически некорректные тексты. Мы не несём за это ответственность."""
|
| 157 |
)
|
| 158 |
+
|
| 159 |
# Pressing Enter
|
| 160 |
submit_event = msg.submit(
|
| 161 |
fn=user,
|
|
|
|
| 207 |
clear.click(lambda: None, None, chatbot, queue=False)
|
| 208 |
|
| 209 |
demo.queue(max_size=128, concurrency_count=1)
|
| 210 |
+
demo.launch(share=True)
|