Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,30 @@
|
|
| 1 |
|
| 2 |
-
from transformers import AutoTokenizer,
|
| 3 |
import torch
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 10 |
|
| 11 |
-
# Функция генерации ответа
|
| 12 |
def generate_response(prompt):
|
| 13 |
-
input_ids = tokenizer.encode(prompt, return_tensors="pt"
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 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(
|
| 32 |
outputs=gr.Textbox(label="Ответ модели"),
|
| 33 |
title="Интерфейс ChatGPT",
|
| 34 |
description="Пример взаимодействия с API OpenAI через Hugging Face Space"
|
|
|
|
| 1 |
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import torch
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
model_name = "sberbank-ai/rugpt3medium_based_on_gpt2"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
|
|
|
| 9 |
|
|
|
|
| 10 |
def generate_response(prompt):
|
| 11 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
| 12 |
+
output = model.generate(
|
| 13 |
+
input_ids,
|
| 14 |
+
max_length=200,
|
| 15 |
+
num_return_sequences=1,
|
| 16 |
+
do_sample=True,
|
| 17 |
+
top_k=50,
|
| 18 |
+
top_p=0.95,
|
| 19 |
+
temperature=0.9,
|
| 20 |
+
pad_token_id=tokenizer.eos_token_id
|
| 21 |
+
)
|
| 22 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
|
|
|
| 23 |
return response
|
| 24 |
|
|
|
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=generate_response,
|
| 27 |
+
inputs=gr.Textbox(label="Введите ваш вопрос"),
|
| 28 |
outputs=gr.Textbox(label="Ответ модели"),
|
| 29 |
title="Интерфейс ChatGPT",
|
| 30 |
description="Пример взаимодействия с API OpenAI через Hugging Face Space"
|