diff --git a/app/main.py b/app/main.py index b99c0ba..8fd4c8d 100644 --- a/app/main.py +++ b/app/main.py @@ -171,6 +171,12 @@ def main(): def initialize_model(selected_model_key): """Создаёт или перезагружает экземпляр ChatWithAI с выбранной моделью.""" nonlocal chat + if chat is not None: + logger.info(f"Смена модели") + # Удаляем экземпляр + del chat + torch.cuda.empty_cache() + model_path = MODEL_OPTIONS[selected_model_key] try: chat = ChatWithAI(model_path) @@ -183,12 +189,7 @@ def main(): gr.update(visible=False), \ f"❌ Ошибка загрузки модели: {str(e)}" - def respond(message, history, model_choice): - nonlocal chat - if chat is None: - yield "Сначала выберите модель и дождитесь загрузки." - return - + def respond(message, history): # Генерируем ответ по частям for token in chat.generate_response_stream(message): yield token @@ -217,7 +218,6 @@ def main(): label="Чат", height=600, bubble_full_width=False, - avatar_images=("./user_avatar.png", "./bot_avatar.png") ) msg = gr.Textbox( label="Сообщение", @@ -236,7 +236,7 @@ def main(): # Отправка сообщения msg.submit( respond, - inputs=[msg, chatbot, model_dropdown], + inputs=[msg, chatbot], outputs=[chatbot] )