File size: 1,009 Bytes
34122ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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()