Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,30 +4,31 @@ import torch
|
|
4 |
import gradio as gr
|
5 |
|
6 |
# Загружаем токенизатор и модель
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
-
#
|
11 |
-
def
|
12 |
-
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
13 |
with torch.no_grad():
|
14 |
-
|
15 |
input_ids,
|
16 |
max_length=200,
|
|
|
17 |
do_sample=True,
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
pad_token_id=tokenizer.eos_token_id
|
23 |
)
|
24 |
-
response = tokenizer.decode(
|
25 |
return response
|
26 |
|
27 |
-
#
|
28 |
iface = gr.Interface(
|
29 |
-
fn=
|
30 |
-
inputs=gr.Textbox(label="Введите ваш запрос"),
|
31 |
outputs=gr.Textbox(label="Ответ от ChatGPT"),
|
32 |
title="Интерфейс ChatGPT",
|
33 |
description="Пример взаимодействия с API OpenAI через Hugging Face Space"
|
|
|
4 |
import gradio as gr
|
5 |
|
6 |
# Загружаем токенизатор и модель
|
7 |
+
model_name = "cointegrated/rut5-base"
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
10 |
|
11 |
+
# Функция генерации ответа
|
12 |
+
def generate_response(prompt):
|
13 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt", max_length=512, truncation=True)
|
14 |
with torch.no_grad():
|
15 |
+
output_ids = model.generate(
|
16 |
input_ids,
|
17 |
max_length=200,
|
18 |
+
num_beams=5,
|
19 |
do_sample=True,
|
20 |
+
top_p=0.9,
|
21 |
+
temperature=0.8,
|
22 |
+
pad_token_id=tokenizer.pad_token_id,
|
23 |
+
eos_token_id=tokenizer.eos_token_id
|
|
|
24 |
)
|
25 |
+
response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
26 |
return response
|
27 |
|
28 |
+
# Gradio-интерфейс
|
29 |
iface = gr.Interface(
|
30 |
+
fn=generate_response,
|
31 |
+
inputs=gr.Textbox(lines=4, label="Введите ваш запрос"),
|
32 |
outputs=gr.Textbox(label="Ответ от ChatGPT"),
|
33 |
title="Интерфейс ChatGPT",
|
34 |
description="Пример взаимодействия с API OpenAI через Hugging Face Space"
|