Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,31 +4,31 @@ from transformers import pipeline
|
|
4 |
|
5 |
# Инициализация моделей
|
6 |
models = {
|
7 |
-
"
|
8 |
"text-generation",
|
9 |
-
model="
|
10 |
-
tokenizer="
|
11 |
device=-1
|
12 |
),
|
13 |
-
"
|
14 |
"text-generation",
|
15 |
-
model="ai-
|
16 |
-
tokenizer="ai-
|
17 |
device=-1
|
18 |
),
|
19 |
-
"
|
20 |
"text-generation",
|
21 |
-
model="
|
22 |
-
tokenizer="
|
23 |
device=-1
|
24 |
)
|
25 |
}
|
26 |
|
27 |
-
#
|
28 |
def build_simple_prompt(user_input):
|
29 |
return f"Клиент: {user_input}\nКатегория обращения:"
|
30 |
|
31 |
-
#
|
32 |
def build_cot_prompt(user_input):
|
33 |
return (
|
34 |
f"Клиент: {user_input}\n"
|
@@ -39,7 +39,7 @@ def build_cot_prompt(user_input):
|
|
39 |
"На основе анализа, укажи категорию обращения:"
|
40 |
)
|
41 |
|
42 |
-
# Генерация
|
43 |
def generate_classification(user_input):
|
44 |
prompt_simple = build_simple_prompt(user_input)
|
45 |
prompt_cot = build_cot_prompt(user_input)
|
@@ -49,12 +49,12 @@ def generate_classification(user_input):
|
|
49 |
for name, pipe in models.items():
|
50 |
# CoT ответ
|
51 |
start_cot = time.time()
|
52 |
-
cot_output = pipe(prompt_cot, max_new_tokens=
|
53 |
end_cot = round(time.time() - start_cot, 2)
|
54 |
|
55 |
# Обычный ответ
|
56 |
start_simple = time.time()
|
57 |
-
simple_output = pipe(prompt_simple, max_new_tokens=
|
58 |
end_simple = round(time.time() - start_simple, 2)
|
59 |
|
60 |
results[name] = {
|
@@ -65,34 +65,37 @@ def generate_classification(user_input):
|
|
65 |
}
|
66 |
|
67 |
return (
|
68 |
-
results["
|
69 |
-
results["
|
70 |
-
results["
|
71 |
-
results["
|
72 |
-
results["
|
73 |
-
results["
|
74 |
)
|
75 |
|
76 |
# Gradio UI
|
77 |
-
with gr.Blocks(
|
78 |
-
gr.Markdown("🏦
|
79 |
|
80 |
-
inp = gr.Textbox(label="Вопрос клиента", placeholder="Например: Я не могу перевести деньги
|
81 |
btn = gr.Button("Сгенерировать")
|
82 |
|
83 |
-
|
|
|
84 |
cot1 = gr.Textbox(label="CoT ответ")
|
85 |
cot1_time = gr.Textbox(label="Время CoT")
|
86 |
simple1 = gr.Textbox(label="Обычный от��ет")
|
87 |
simple1_time = gr.Textbox(label="Время обычного")
|
88 |
|
89 |
-
|
|
|
90 |
cot2 = gr.Textbox(label="CoT ответ")
|
91 |
cot2_time = gr.Textbox(label="Время CoT")
|
92 |
simple2 = gr.Textbox(label="Обычный ответ")
|
93 |
simple2_time = gr.Textbox(label="Время обычного")
|
94 |
|
95 |
-
|
|
|
96 |
cot3 = gr.Textbox(label="CoT ответ")
|
97 |
cot3_time = gr.Textbox(label="Время CoT")
|
98 |
simple3 = gr.Textbox(label="Обычный ответ")
|
|
|
4 |
|
5 |
# Инициализация моделей
|
6 |
models = {
|
7 |
+
"ChatGPT-like": pipeline(
|
8 |
"text-generation",
|
9 |
+
model="Gre8o8nta/ChatGPT",
|
10 |
+
tokenizer="Gre8o8nta/ChatGPT",
|
11 |
device=-1
|
12 |
),
|
13 |
+
"DeepSeek-like": pipeline(
|
14 |
"text-generation",
|
15 |
+
model="deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
|
16 |
+
tokenizer="deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
|
17 |
device=-1
|
18 |
),
|
19 |
+
"GigaChat-like": pipeline(
|
20 |
"text-generation",
|
21 |
+
model="IlyaGusev/saiga_mistral_7b_text",
|
22 |
+
tokenizer="IlyaGusev/saiga_mistral_7b_text",
|
23 |
device=-1
|
24 |
)
|
25 |
}
|
26 |
|
27 |
+
# Промпт простой
|
28 |
def build_simple_prompt(user_input):
|
29 |
return f"Клиент: {user_input}\nКатегория обращения:"
|
30 |
|
31 |
+
# Промпт с рассуждением
|
32 |
def build_cot_prompt(user_input):
|
33 |
return (
|
34 |
f"Клиент: {user_input}\n"
|
|
|
39 |
"На основе анализа, укажи категорию обращения:"
|
40 |
)
|
41 |
|
42 |
+
# Генерация ответов
|
43 |
def generate_classification(user_input):
|
44 |
prompt_simple = build_simple_prompt(user_input)
|
45 |
prompt_cot = build_cot_prompt(user_input)
|
|
|
49 |
for name, pipe in models.items():
|
50 |
# CoT ответ
|
51 |
start_cot = time.time()
|
52 |
+
cot_output = pipe(prompt_cot, max_new_tokens=150, do_sample=True, top_p=0.9, temperature=0.7)[0]["generated_text"]
|
53 |
end_cot = round(time.time() - start_cot, 2)
|
54 |
|
55 |
# Обычный ответ
|
56 |
start_simple = time.time()
|
57 |
+
simple_output = pipe(prompt_simple, max_new_tokens=80, do_sample=True, top_p=0.9, temperature=0.7)[0]["generated_text"]
|
58 |
end_simple = round(time.time() - start_simple, 2)
|
59 |
|
60 |
results[name] = {
|
|
|
65 |
}
|
66 |
|
67 |
return (
|
68 |
+
results["ChatGPT-like"]["cot_answer"], f"{results['ChatGPT-like']['cot_time']} сек",
|
69 |
+
results["ChatGPT-like"]["simple_answer"], f"{results['ChatGPT-like']['simple_time']} сек",
|
70 |
+
results["DeepSeek-like"]["cot_answer"], f"{results['DeepSeek-like']['cot_time']} сек",
|
71 |
+
results["DeepSeek-like"]["simple_answer"], f"{results['DeepSeek-like']['simple_time']} сек",
|
72 |
+
results["GigaChat-like"]["cot_answer"], f"{results['GigaChat-like']['cot_time']} сек",
|
73 |
+
results["GigaChat-like"]["simple_answer"], f"{results['GigaChat-like']['simple_time']} сек"
|
74 |
)
|
75 |
|
76 |
# Gradio UI
|
77 |
+
with gr.Blocks() as demo:
|
78 |
+
gr.Markdown("🏦 **Сравнение моделей ChatGPT, DeepSeek и GigaChat по классификации банковских обращений (CoT и обычный)**")
|
79 |
|
80 |
+
inp = gr.Textbox(label="Вопрос клиента", placeholder="Например: Я не могу перевести деньги", lines=2)
|
81 |
btn = gr.Button("Сгенерировать")
|
82 |
|
83 |
+
# ChatGPT-like
|
84 |
+
gr.Markdown("### ChatGPT-like")
|
85 |
cot1 = gr.Textbox(label="CoT ответ")
|
86 |
cot1_time = gr.Textbox(label="Время CoT")
|
87 |
simple1 = gr.Textbox(label="Обычный от��ет")
|
88 |
simple1_time = gr.Textbox(label="Время обычного")
|
89 |
|
90 |
+
# DeepSeek-like
|
91 |
+
gr.Markdown("### DeepSeek-like")
|
92 |
cot2 = gr.Textbox(label="CoT ответ")
|
93 |
cot2_time = gr.Textbox(label="Время CoT")
|
94 |
simple2 = gr.Textbox(label="Обычный ответ")
|
95 |
simple2_time = gr.Textbox(label="Время обычного")
|
96 |
|
97 |
+
# GigaChat-like
|
98 |
+
gr.Markdown("### GigaChat-like (заменена на Saiga)")
|
99 |
cot3 = gr.Textbox(label="CoT ответ")
|
100 |
cot3_time = gr.Textbox(label="Время CoT")
|
101 |
simple3 = gr.Textbox(label="Обычный ответ")
|