Spaces:
Running
Running
X commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,10 +55,10 @@ def check_if_pro(token):
|
|
| 55 |
def generate_response(message, history, username, current_chat_id):
|
| 56 |
if not username:
|
| 57 |
gr.Warning("Сначала введите имя пользователя!")
|
| 58 |
-
return history, gr.update(), current_chat_id
|
| 59 |
|
| 60 |
if not message.strip():
|
| 61 |
-
return history, gr.update(), current_chat_id
|
| 62 |
|
| 63 |
history = history + [{"role": "user", "content": message}]
|
| 64 |
|
|
@@ -97,8 +97,8 @@ def generate_response(message, history, username, current_chat_id):
|
|
| 97 |
history_data[current_chat_id]["messages"] = history
|
| 98 |
save_history(username, history_data)
|
| 99 |
|
| 100 |
-
# Возвращаем обновленный список чатов вместе с ответом
|
| 101 |
chat_list_choices = get_chat_list(username)
|
|
|
|
| 102 |
return history, gr.update(value=""), current_chat_id, gr.update(choices=chat_list_choices)
|
| 103 |
|
| 104 |
# === УПРАВЛЕНИЕ ЧАТАМИ ===
|
|
@@ -221,8 +221,8 @@ with gr.Blocks(title="OpenAirAI-X Chat") as demo:
|
|
| 221 |
pro_badge = gr.HTML('<div class="pro-badge">👑 PRO</div>', visible=False)
|
| 222 |
new_chat_btn = gr.Button("➕ Новый чат", variant="primary")
|
| 223 |
gr.Markdown("### 📚 История чатов")
|
| 224 |
-
# Используем
|
| 225 |
-
chat_list = gr.
|
| 226 |
delete_chat_btn = gr.Button("🗑️ Удалить выбранный чат", variant="stop", size="sm")
|
| 227 |
logout_btn = gr.Button("🚪 Выйти", size="sm")
|
| 228 |
|
|
@@ -245,7 +245,7 @@ with gr.Blocks(title="OpenAirAI-X Chat") as demo:
|
|
| 245 |
def handle_login(username, token):
|
| 246 |
if not username.strip():
|
| 247 |
gr.Warning("Введите имя пользователя!")
|
| 248 |
-
return gr.update(), gr.update(), "Не авторизован", "", {}, None, gr.update(choices=[]), gr.update(visible=False)
|
| 249 |
|
| 250 |
is_pro = check_if_pro(token)
|
| 251 |
history_data = load_history(username)
|
|
@@ -285,7 +285,7 @@ with gr.Blocks(title="OpenAirAI-X Chat") as demo:
|
|
| 285 |
"",
|
| 286 |
{},
|
| 287 |
None,
|
| 288 |
-
gr.update(choices=[]),
|
| 289 |
gr.update(visible=False)
|
| 290 |
)
|
| 291 |
|
|
@@ -295,7 +295,6 @@ with gr.Blocks(title="OpenAirAI-X Chat") as demo:
|
|
| 295 |
outputs=[main_interface, login_screen, user_info, username_state, history_state, current_chat_id_state, chat_list, pro_badge]
|
| 296 |
)
|
| 297 |
|
| 298 |
-
# Объединяем генерацию и обновление списка в одну функцию для надежности
|
| 299 |
send_btn.click(
|
| 300 |
fn=generate_response,
|
| 301 |
inputs=[msg_input, chatbot, username_state, current_chat_id_state],
|
|
|
|
| 55 |
def generate_response(message, history, username, current_chat_id):
|
| 56 |
if not username:
|
| 57 |
gr.Warning("Сначала введите имя пользователя!")
|
| 58 |
+
return history, gr.update(), current_chat_id, gr.update()
|
| 59 |
|
| 60 |
if not message.strip():
|
| 61 |
+
return history, gr.update(), current_chat_id, gr.update()
|
| 62 |
|
| 63 |
history = history + [{"role": "user", "content": message}]
|
| 64 |
|
|
|
|
| 97 |
history_data[current_chat_id]["messages"] = history
|
| 98 |
save_history(username, history_data)
|
| 99 |
|
|
|
|
| 100 |
chat_list_choices = get_chat_list(username)
|
| 101 |
+
# Возвращаем обновленный список через gr.update
|
| 102 |
return history, gr.update(value=""), current_chat_id, gr.update(choices=chat_list_choices)
|
| 103 |
|
| 104 |
# === УПРАВЛЕНИЕ ЧАТАМИ ===
|
|
|
|
| 221 |
pro_badge = gr.HTML('<div class="pro-badge">👑 PRO</div>', visible=False)
|
| 222 |
new_chat_btn = gr.Button("➕ Новый чат", variant="primary")
|
| 223 |
gr.Markdown("### 📚 История чатов")
|
| 224 |
+
# Используем Dropdown с allow_custom_value=False для стабильности
|
| 225 |
+
chat_list = gr.Dropdown(choices=[], label="Ваши чаты", interactive=True, allow_custom_value=False, value=None)
|
| 226 |
delete_chat_btn = gr.Button("🗑️ Удалить выбранный чат", variant="stop", size="sm")
|
| 227 |
logout_btn = gr.Button("🚪 Выйти", size="sm")
|
| 228 |
|
|
|
|
| 245 |
def handle_login(username, token):
|
| 246 |
if not username.strip():
|
| 247 |
gr.Warning("Введите имя пользователя!")
|
| 248 |
+
return gr.update(), gr.update(), "Не авторизован", "", {}, None, gr.update(choices=[], value=None), gr.update(visible=False)
|
| 249 |
|
| 250 |
is_pro = check_if_pro(token)
|
| 251 |
history_data = load_history(username)
|
|
|
|
| 285 |
"",
|
| 286 |
{},
|
| 287 |
None,
|
| 288 |
+
gr.update(choices=[], value=None),
|
| 289 |
gr.update(visible=False)
|
| 290 |
)
|
| 291 |
|
|
|
|
| 295 |
outputs=[main_interface, login_screen, user_info, username_state, history_state, current_chat_id_state, chat_list, pro_badge]
|
| 296 |
)
|
| 297 |
|
|
|
|
| 298 |
send_btn.click(
|
| 299 |
fn=generate_response,
|
| 300 |
inputs=[msg_input, chatbot, username_state, current_chat_id_state],
|