import gradio as gr from transformers import AutoTokenizer, AutoModelForCausalLM # Загрузка токенизатора и модели tokenizer = AutoTokenizer.from_pretrained("ai-forever/ruGPT-3.5-13B") model = AutoModelForCausalLM.from_pretrained("ai-forever/ruGPT-3.5-13B") # Определение функции для обработки вопроса и генерации ответа def generate_response(question): # Кодирование вопроса в токены input_ids = tokenizer.encode(question, return_tensors="pt") # Генерация ответа от модели output = model.generate(input_ids) # Декодирование ответа из токенов в текст decoded_output = tokenizer.decode(output[0], skip_special_tokens=True) return decoded_output # Создание интерфейса Gradio iface = gr.Interface(fn=generate_response, inputs="text", outputs="text") # Запуск веб-сайта iface.launch()