Spaces:
Runtime error
Runtime error
Commit
·
902588d
1
Parent(s):
83c961c
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,19 +5,16 @@ from transformers import (
|
|
| 5 |
pipeline,
|
| 6 |
AutoTokenizer,
|
| 7 |
TextIteratorStreamer,
|
| 8 |
-
BitsAndBytesConfig
|
| 9 |
)
|
| 10 |
|
| 11 |
|
| 12 |
def chat_history(history) -> str:
|
| 13 |
-
messages = [
|
| 14 |
-
{
|
| 15 |
-
"role": ("user" if i % 2 == 0 else "assistant"),
|
| 16 |
-
"content": dialog[i % 2]
|
| 17 |
-
}
|
| 18 |
-
for i, dialog in enumerate(history) for _ in (0, 1) if dialog[i % 2]
|
| 19 |
-
]
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
return pipe.tokenizer.apply_chat_template(
|
| 22 |
messages, tokenize=False, add_generation_prompt=True
|
| 23 |
)
|
|
@@ -45,7 +42,7 @@ def launch_app(pipe, streamer):
|
|
| 45 |
clear = gr.Button("Clear")
|
| 46 |
|
| 47 |
def user(user_message, history):
|
| 48 |
-
return "", history + [[user_message,
|
| 49 |
|
| 50 |
def bot(history):
|
| 51 |
prompt = chat_history(history)
|
|
|
|
| 5 |
pipeline,
|
| 6 |
AutoTokenizer,
|
| 7 |
TextIteratorStreamer,
|
|
|
|
| 8 |
)
|
| 9 |
|
| 10 |
|
| 11 |
def chat_history(history) -> str:
|
| 12 |
+
messages = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
for dialog in history:
|
| 15 |
+
for i, message in enumerate(dialog):
|
| 16 |
+
role = "user" if i % 2 == 0 else "assistant"
|
| 17 |
+
messages.append({"role": role, "content": message})
|
| 18 |
return pipe.tokenizer.apply_chat_template(
|
| 19 |
messages, tokenize=False, add_generation_prompt=True
|
| 20 |
)
|
|
|
|
| 42 |
clear = gr.Button("Clear")
|
| 43 |
|
| 44 |
def user(user_message, history):
|
| 45 |
+
return "", history + [[user_message, ""]]
|
| 46 |
|
| 47 |
def bot(history):
|
| 48 |
prompt = chat_history(history)
|