Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
-
import torch
|
4 |
|
5 |
-
# Настройка 4-битной квантизации
|
6 |
-
quantization_config = BitsAndBytesConfig(
|
7 |
-
load_in_4bit=True,
|
8 |
-
bnb_4bit_compute_dtype=torch.float16, #
|
9 |
-
bnb_4bit_quant_type="nf4",
|
10 |
-
bnb_4bit_use_double_quant=True
|
11 |
-
)
|
12 |
-
|
13 |
-
# Загрузка модели и токенизатора
|
14 |
model_name = "IlyaGusev/saiga_yandexgpt_8b"
|
15 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
16 |
-
model = AutoModelForCausalLM.from_pretrained(
|
17 |
-
model_name,
|
18 |
-
quantization_config=quantization_config,
|
19 |
-
device_map="auto"
|
20 |
-
)
|
21 |
|
22 |
-
# Функция для генерации текста
|
23 |
def generate_text(input_text):
|
24 |
-
inputs = tokenizer(input_text, return_tensors="pt")
|
25 |
outputs = model.generate(
|
26 |
**inputs,
|
27 |
max_new_tokens=300,
|
28 |
do_sample=True,
|
29 |
-
temperature=0.7
|
30 |
)
|
31 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
32 |
|
33 |
-
# Создание интерфейса Gradio
|
34 |
interface = gr.Interface(
|
35 |
fn=generate_text,
|
36 |
inputs=gr.Textbox(lines=2, placeholder="Введите ваш запрос..."),
|
37 |
outputs="text",
|
38 |
-
title="Saiga YandexGPT 8B Demo
|
39 |
-
description="Задайте вопрос модели Saiga YandexGPT 8B
|
40 |
)
|
41 |
|
42 |
-
# Запуск приложения
|
43 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
model_name = "IlyaGusev/saiga_yandexgpt_8b"
|
5 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
7 |
|
|
|
8 |
def generate_text(input_text):
|
9 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
10 |
outputs = model.generate(
|
11 |
**inputs,
|
12 |
max_new_tokens=300,
|
13 |
do_sample=True,
|
14 |
+
temperature=0.7
|
15 |
)
|
16 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
17 |
|
|
|
18 |
interface = gr.Interface(
|
19 |
fn=generate_text,
|
20 |
inputs=gr.Textbox(lines=2, placeholder="Введите ваш запрос..."),
|
21 |
outputs="text",
|
22 |
+
title="Saiga YandexGPT 8B Demo",
|
23 |
+
description="Задайте вопрос модели Saiga YandexGPT 8B!"
|
24 |
)
|
25 |
|
|
|
26 |
interface.launch()
|