SimrusDenuvo commited on
Commit
240efaf
·
verified ·
1 Parent(s): d1231ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -35
app.py CHANGED
@@ -2,12 +2,12 @@ import gradio as gr
2
  import time
3
  from transformers import pipeline
4
 
5
- # Инициализация моделей (CPU-совместимые)
6
  models = {
7
  "ChatGPT-like": pipeline(
8
  "text-generation",
9
- model="IlyaGusev/saiga_mistral_7b_text",
10
- tokenizer="IlyaGusev/saiga_mistral_7b_text",
11
  device=-1
12
  ),
13
  "DeepSeek-like": pipeline(
@@ -18,84 +18,82 @@ models = {
18
  ),
19
  "GigaChat-like": pipeline(
20
  "text-generation",
21
- model="tinkoff-ai/ruGPT3Large",
22
- tokenizer="tinkoff-ai/ruGPT3Large",
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"
35
- "Проанализируй обращение клиента пошагово:\n"
36
- "1. В чём проблема?\n"
37
- "2. Почему она возникла?\n"
38
- "3. Как это можно решить?\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)
46
 
47
  results = {}
48
-
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
  # Simple
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] = {
61
- "cot_answer": cot_output.strip(),
62
- "cot_time": end_cot,
63
- "simple_answer": simple_output.strip(),
64
- "simple_time": end_simple
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 интерфейс
77
  with gr.Blocks() as demo:
78
- gr.Markdown("## 🧠 Сравнение моделей (ChatGPT, DeepSeek, GigaChat) по классификации клиентских обращений")
79
 
80
  inp = gr.Textbox(label="Вопрос клиента", placeholder="Например: Я не могу перевести деньги", lines=2)
81
  btn = gr.Button("Сгенерировать")
82
 
83
- # ChatGPT-like
84
- gr.Markdown("### ChatGPT-like (Saiga Mistral)")
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 (ruGPT3Large)")
99
  cot3 = gr.Textbox(label="CoT ответ")
100
  cot3_time = gr.Textbox(label="Время CoT")
101
  simple3 = gr.Textbox(label="Обычный ответ")
 
2
  import time
3
  from transformers import pipeline
4
 
5
+ # Инициализация моделей
6
  models = {
7
  "ChatGPT-like": pipeline(
8
  "text-generation",
9
+ model="OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
10
+ tokenizer="OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
11
  device=-1
12
  ),
13
  "DeepSeek-like": pipeline(
 
18
  ),
19
  "GigaChat-like": pipeline(
20
  "text-generation",
21
+ model="tinkoff-ai/ruDialoGPT-medium",
22
+ tokenizer="tinkoff-ai/ruDialoGPT-medium",
23
  device=-1
24
  )
25
  }
26
 
27
+ # Промпты
28
  def build_simple_prompt(user_input):
29
  return f"Клиент: {user_input}\nКатегория обращения:"
30
 
 
31
  def build_cot_prompt(user_input):
32
  return (
33
  f"Клиент: {user_input}\n"
34
+ "Проанализируй обращение пошагово:\n"
35
+ "1. В чём суть проблемы?\n"
36
+ "2. Возможные причины?\n"
37
+ "3. Решение?\n"
38
+ "Вывод: категория обращения:"
39
  )
40
 
41
+ # Генерация ответов
42
  def generate_classification(user_input):
43
  prompt_simple = build_simple_prompt(user_input)
44
  prompt_cot = build_cot_prompt(user_input)
45
 
46
  results = {}
 
47
  for name, pipe in models.items():
48
  # CoT
49
  start_cot = time.time()
50
+ cot_out = pipe(prompt_cot, max_new_tokens=150, do_sample=True, top_p=0.9, temperature=0.7)[0]["generated_text"]
51
+ time_cot = round(time.time() - start_cot, 2)
52
 
53
  # Simple
54
  start_simple = time.time()
55
+ simple_out = pipe(prompt_simple, max_new_tokens=80, do_sample=True, top_p=0.9, temperature=0.7)[0]["generated_text"]
56
+ time_simple = round(time.time() - start_simple, 2)
57
 
58
  results[name] = {
59
+ "cot": cot_out.strip(),
60
+ "cot_time": time_cot,
61
+ "simple": simple_out.strip(),
62
+ "simple_time": time_simple
63
  }
64
 
65
  return (
66
+ results["ChatGPT-like"]["cot"], f"{results['ChatGPT-like']['cot_time']} сек",
67
+ results["ChatGPT-like"]["simple"], f"{results['ChatGPT-like']['simple_time']} сек",
68
+ results["DeepSeek-like"]["cot"], f"{results['DeepSeek-like']['cot_time']} сек",
69
+ results["DeepSeek-like"]["simple"], f"{results['DeepSeek-like']['simple_time']} сек",
70
+ results["GigaChat-like"]["cot"], f"{results['GigaChat-like']['cot_time']} сек",
71
+ results["GigaChat-like"]["simple"], f"{results['GigaChat-like']['simple_time']} сек"
72
  )
73
 
74
+ # Интерфейс
75
  with gr.Blocks() as demo:
76
+ gr.Markdown("## 🤖 Сравнение моделей: ChatGPT, DeepSeek, GigaChat классификация банковских обращений")
77
 
78
  inp = gr.Textbox(label="Вопрос клиента", placeholder="Например: Я не могу перевести деньги", lines=2)
79
  btn = gr.Button("Сгенерировать")
80
 
81
+ # ChatGPT
82
+ gr.Markdown("### ChatGPT-like (OpenAssistant)")
83
  cot1 = gr.Textbox(label="CoT ответ")
84
  cot1_time = gr.Textbox(label="Время CoT")
85
  simple1 = gr.Textbox(label="Обычный ответ")
86
  simple1_time = gr.Textbox(label="Время обычного")
87
 
88
+ # DeepSeek
89
  gr.Markdown("### DeepSeek-like")
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
+ # GigaChat
96
+ gr.Markdown("### GigaChat-like (ruDialoGPT)")
97
  cot3 = gr.Textbox(label="CoT ответ")
98
  cot3_time = gr.Textbox(label="Время CoT")
99
  simple3 = gr.Textbox(label="Обычный ответ")