Spaces:
Runtime error
Runtime error
X commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,9 +60,7 @@ def generate_response(message, history, username, current_chat_id):
|
|
| 60 |
return history, gr.update(), current_chat_id
|
| 61 |
|
| 62 |
# Новый формат Gradio 6+: список словарей
|
| 63 |
-
history = history + [
|
| 64 |
-
{"role": "user", "content": message},
|
| 65 |
-
]
|
| 66 |
|
| 67 |
# Формируем промпт из всей истории
|
| 68 |
prompt = ""
|
|
@@ -87,7 +85,6 @@ def generate_response(message, history, username, current_chat_id):
|
|
| 87 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 88 |
ai_response = response.split("AI:")[-1].strip()
|
| 89 |
|
| 90 |
-
# Добавляем ответ AI
|
| 91 |
history = history + [{"role": "assistant", "content": ai_response}]
|
| 92 |
|
| 93 |
# Сохраняем в хранилище
|
|
@@ -181,7 +178,7 @@ CUSTOM_CSS = """
|
|
| 181 |
"""
|
| 182 |
|
| 183 |
# === ИНТЕРФЕЙС ===
|
| 184 |
-
with gr.Blocks(title="OpenAirAI-X Chat") as demo:
|
| 185 |
|
| 186 |
# Состояния
|
| 187 |
username_state = gr.State("")
|
|
@@ -221,7 +218,6 @@ with gr.Blocks(title="OpenAirAI-X Chat") as demo:
|
|
| 221 |
chatbot = gr.Chatbot(
|
| 222 |
label="Диалог",
|
| 223 |
height=500,
|
| 224 |
-
show_copy_button=True,
|
| 225 |
type="messages"
|
| 226 |
)
|
| 227 |
with gr.Row():
|
|
@@ -279,13 +275,13 @@ with gr.Blocks(title="OpenAirAI-X Chat") as demo:
|
|
| 279 |
display_name = f"👤 {username}"
|
| 280 |
|
| 281 |
return (
|
| 282 |
-
gr.update(visible=True),
|
| 283 |
-
gr.update(visible=False),
|
| 284 |
-
display_name,
|
| 285 |
-
username,
|
| 286 |
-
history_data,
|
| 287 |
-
current_chat_id,
|
| 288 |
-
chat_list_choices,
|
| 289 |
gr.update(visible=is_pro, value=pro_badge_html)
|
| 290 |
)
|
| 291 |
return (gr.update(), gr.update(), gr.update(), "", {}, None, [], gr.update())
|
|
@@ -302,7 +298,6 @@ with gr.Blocks(title="OpenAirAI-X Chat") as demo:
|
|
| 302 |
gr.update(visible=False)
|
| 303 |
)
|
| 304 |
|
| 305 |
-
# При загрузке страницы проверяем авторизацию
|
| 306 |
demo.load(
|
| 307 |
fn=handle_login,
|
| 308 |
inputs=None,
|
|
@@ -310,7 +305,6 @@ with gr.Blocks(title="OpenAirAI-X Chat") as demo:
|
|
| 310 |
history_state, current_chat_id_state, chat_list, pro_badge]
|
| 311 |
)
|
| 312 |
|
| 313 |
-
# Отправка сообщения
|
| 314 |
send_btn.click(
|
| 315 |
fn=generate_response,
|
| 316 |
inputs=[msg_input, chatbot, username_state, current_chat_id_state],
|
|
@@ -331,28 +325,24 @@ with gr.Blocks(title="OpenAirAI-X Chat") as demo:
|
|
| 331 |
outputs=[chat_list]
|
| 332 |
)
|
| 333 |
|
| 334 |
-
# Новый чат
|
| 335 |
new_chat_btn.click(
|
| 336 |
fn=new_chat,
|
| 337 |
inputs=[username_state],
|
| 338 |
outputs=[chatbot, current_chat_id_state, chat_list]
|
| 339 |
)
|
| 340 |
|
| 341 |
-
# Загрузка чата
|
| 342 |
chat_list.change(
|
| 343 |
fn=load_chat,
|
| 344 |
inputs=[chat_list, username_state, current_chat_id_state],
|
| 345 |
outputs=[chatbot, current_chat_id_state]
|
| 346 |
)
|
| 347 |
|
| 348 |
-
# Удаление чата
|
| 349 |
delete_chat_btn.click(
|
| 350 |
fn=delete_chat,
|
| 351 |
inputs=[chat_list, username_state],
|
| 352 |
outputs=[chatbot, history_state, current_chat_id_state, chat_list]
|
| 353 |
)
|
| 354 |
|
| 355 |
-
# Выход
|
| 356 |
logout_btn.click(
|
| 357 |
fn=handle_logout,
|
| 358 |
inputs=None,
|
|
@@ -360,5 +350,4 @@ with gr.Blocks(title="OpenAirAI-X Chat") as demo:
|
|
| 360 |
history_state, current_chat_id_state, chat_list, pro_badge]
|
| 361 |
)
|
| 362 |
|
| 363 |
-
|
| 364 |
-
demo.launch(server_name="0.0.0.0", server_port=7860, css=CUSTOM_CSS)
|
|
|
|
| 60 |
return history, gr.update(), current_chat_id
|
| 61 |
|
| 62 |
# Новый формат Gradio 6+: список словарей
|
| 63 |
+
history = history + [{"role": "user", "content": message}]
|
|
|
|
|
|
|
| 64 |
|
| 65 |
# Формируем промпт из всей истории
|
| 66 |
prompt = ""
|
|
|
|
| 85 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 86 |
ai_response = response.split("AI:")[-1].strip()
|
| 87 |
|
|
|
|
| 88 |
history = history + [{"role": "assistant", "content": ai_response}]
|
| 89 |
|
| 90 |
# Сохраняем в хранилище
|
|
|
|
| 178 |
"""
|
| 179 |
|
| 180 |
# === ИНТЕРФЕЙС ===
|
| 181 |
+
with gr.Blocks(css=CUSTOM_CSS, title="OpenAirAI-X Chat") as demo:
|
| 182 |
|
| 183 |
# Состояния
|
| 184 |
username_state = gr.State("")
|
|
|
|
| 218 |
chatbot = gr.Chatbot(
|
| 219 |
label="Диалог",
|
| 220 |
height=500,
|
|
|
|
| 221 |
type="messages"
|
| 222 |
)
|
| 223 |
with gr.Row():
|
|
|
|
| 275 |
display_name = f"👤 {username}"
|
| 276 |
|
| 277 |
return (
|
| 278 |
+
gr.update(visible=True),
|
| 279 |
+
gr.update(visible=False),
|
| 280 |
+
display_name,
|
| 281 |
+
username,
|
| 282 |
+
history_data,
|
| 283 |
+
current_chat_id,
|
| 284 |
+
chat_list_choices,
|
| 285 |
gr.update(visible=is_pro, value=pro_badge_html)
|
| 286 |
)
|
| 287 |
return (gr.update(), gr.update(), gr.update(), "", {}, None, [], gr.update())
|
|
|
|
| 298 |
gr.update(visible=False)
|
| 299 |
)
|
| 300 |
|
|
|
|
| 301 |
demo.load(
|
| 302 |
fn=handle_login,
|
| 303 |
inputs=None,
|
|
|
|
| 305 |
history_state, current_chat_id_state, chat_list, pro_badge]
|
| 306 |
)
|
| 307 |
|
|
|
|
| 308 |
send_btn.click(
|
| 309 |
fn=generate_response,
|
| 310 |
inputs=[msg_input, chatbot, username_state, current_chat_id_state],
|
|
|
|
| 325 |
outputs=[chat_list]
|
| 326 |
)
|
| 327 |
|
|
|
|
| 328 |
new_chat_btn.click(
|
| 329 |
fn=new_chat,
|
| 330 |
inputs=[username_state],
|
| 331 |
outputs=[chatbot, current_chat_id_state, chat_list]
|
| 332 |
)
|
| 333 |
|
|
|
|
| 334 |
chat_list.change(
|
| 335 |
fn=load_chat,
|
| 336 |
inputs=[chat_list, username_state, current_chat_id_state],
|
| 337 |
outputs=[chatbot, current_chat_id_state]
|
| 338 |
)
|
| 339 |
|
|
|
|
| 340 |
delete_chat_btn.click(
|
| 341 |
fn=delete_chat,
|
| 342 |
inputs=[chat_list, username_state],
|
| 343 |
outputs=[chatbot, history_state, current_chat_id_state, chat_list]
|
| 344 |
)
|
| 345 |
|
|
|
|
| 346 |
logout_btn.click(
|
| 347 |
fn=handle_logout,
|
| 348 |
inputs=None,
|
|
|
|
| 350 |
history_state, current_chat_id_state, chat_list, pro_badge]
|
| 351 |
)
|
| 352 |
|
| 353 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|