AnatoliiG commited on
Commit ·
1566259
1
Parent(s): bf97fda
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,6 +82,7 @@ def user_input(user_message, history):
|
|
| 82 |
# Если история пуста, инициализируем список
|
| 83 |
if history is None:
|
| 84 |
history = []
|
|
|
|
| 85 |
return "", history + [{"role": "user", "content": user_message}]
|
| 86 |
|
| 87 |
|
|
@@ -102,11 +103,9 @@ def bot_response(history, system_prompt, temperature, max_tokens):
|
|
| 102 |
|
| 103 |
if isinstance(content, list):
|
| 104 |
content = "\n".join(str(item) for item in content)
|
| 105 |
-
# --------------------------
|
| 106 |
|
| 107 |
messages.append({"role": msg["role"], "content": str(content)})
|
| 108 |
|
| 109 |
-
# Добавляем пустой ответ ассистента в историю для стриминга
|
| 110 |
history.append({"role": "assistant", "content": ""})
|
| 111 |
|
| 112 |
partial_text = ""
|
|
@@ -165,7 +164,6 @@ with gr.Blocks(theme=theme, css=custom_css, title="Qwen Coder Pro") as demo:
|
|
| 165 |
label="Conversation",
|
| 166 |
elem_id="chatbot",
|
| 167 |
avatar_images=(None, "https://api.iconify.design/noto:robot.svg"),
|
| 168 |
-
type="messages",
|
| 169 |
)
|
| 170 |
|
| 171 |
msg = gr.Textbox(
|
|
@@ -180,7 +178,7 @@ with gr.Blocks(theme=theme, css=custom_css, title="Qwen Coder Pro") as demo:
|
|
| 180 |
submit_btn.click(user_input, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 181 |
bot_response, [chatbot, system_prompt, temperature, max_tokens], chatbot
|
| 182 |
)
|
| 183 |
-
#
|
| 184 |
clear_btn.click(lambda: [], None, chatbot, queue=False)
|
| 185 |
|
| 186 |
app = mount_gradio_app(app, demo, path="/")
|
|
|
|
| 82 |
# Если история пуста, инициализируем список
|
| 83 |
if history is None:
|
| 84 |
history = []
|
| 85 |
+
# Возвращаем список словарей (формат Gradio 5)
|
| 86 |
return "", history + [{"role": "user", "content": user_message}]
|
| 87 |
|
| 88 |
|
|
|
|
| 103 |
|
| 104 |
if isinstance(content, list):
|
| 105 |
content = "\n".join(str(item) for item in content)
|
|
|
|
| 106 |
|
| 107 |
messages.append({"role": msg["role"], "content": str(content)})
|
| 108 |
|
|
|
|
| 109 |
history.append({"role": "assistant", "content": ""})
|
| 110 |
|
| 111 |
partial_text = ""
|
|
|
|
| 164 |
label="Conversation",
|
| 165 |
elem_id="chatbot",
|
| 166 |
avatar_images=(None, "https://api.iconify.design/noto:robot.svg"),
|
|
|
|
| 167 |
)
|
| 168 |
|
| 169 |
msg = gr.Textbox(
|
|
|
|
| 178 |
submit_btn.click(user_input, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 179 |
bot_response, [chatbot, system_prompt, temperature, max_tokens], chatbot
|
| 180 |
)
|
| 181 |
+
# Очистка возвращает пустой список
|
| 182 |
clear_btn.click(lambda: [], None, chatbot, queue=False)
|
| 183 |
|
| 184 |
app = mount_gradio_app(app, demo, path="/")
|