File size: 775 Bytes
b26c3b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM

# Подключаем модель
model_name = "EleutherAI/gpt-neo-2.7B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Функция генерации текста
def generate_text(prompt):
    input_ids = tokenizer.encode(prompt, return_tensors="pt")
    output = model.generate(input_ids, max_length=100)
    return tokenizer.decode(output[0], skip_special_tokens=True)

# Интерфейс Gradio
interface = gr.Interface(
    fn=generate_text,
    inputs="text",
    outputs="text",
    title="GPT-Neo Bot",
    description="Введите текст, чтобы получить ответ."
)

interface.launch()