fix: split user and bot
Browse files
app.py
CHANGED
@@ -60,9 +60,11 @@ with gr.Blocks() as demo:
|
|
60 |
|
61 |
tokenizer, model = load_model()
|
62 |
|
63 |
-
def
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
bot_message = generate(
|
67 |
tokenizer,
|
68 |
model,
|
@@ -70,10 +72,15 @@ with gr.Blocks() as demo:
|
|
70 |
alpha=alpha,
|
71 |
topk=topk,
|
72 |
)
|
73 |
-
|
|
|
74 |
|
75 |
-
msg.submit(
|
76 |
-
|
|
|
|
|
|
|
|
|
77 |
|
78 |
clear.click(lambda: None, None, chatbot)
|
79 |
|
|
|
60 |
|
61 |
tokenizer, model = load_model()
|
62 |
|
63 |
+
def user(user_message: str, history: list[list[str]]):
|
64 |
+
return "", [*history, [user_message, None]]
|
65 |
+
|
66 |
+
def bot(history: list[list[str]], alpha: float, topk: int):
|
67 |
+
user_message = history[-1][0]
|
68 |
bot_message = generate(
|
69 |
tokenizer,
|
70 |
model,
|
|
|
72 |
alpha=alpha,
|
73 |
topk=topk,
|
74 |
)
|
75 |
+
history[-1][1] = bot_message
|
76 |
+
return history
|
77 |
|
78 |
+
msg.submit(user, inputs=[msg, chatbot], outputs=[msg, chatbot]).then(
|
79 |
+
bot, inputs=[chatbot, alpha, topk], outputs=[chatbot]
|
80 |
+
)
|
81 |
+
button.click(user, inputs=[msg, chatbot], outputs=[msg, chatbot]).then(
|
82 |
+
bot, inputs=[chatbot, alpha, topk], outputs=[chatbot]
|
83 |
+
)
|
84 |
|
85 |
clear.click(lambda: None, None, chatbot)
|
86 |
|