SimrusDenuvo commited on
Commit
60a6dd5
·
verified ·
1 Parent(s): 19236d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -26
app.py CHANGED
@@ -4,31 +4,31 @@ from transformers import pipeline
4
 
5
  # Инициализация моделей
6
  models = {
7
- "ruGPT3-Medium": pipeline(
8
  "text-generation",
9
- model="ai-forever/rugpt3medium_based_on_gpt2",
10
- tokenizer="ai-forever/rugpt3medium_based_on_gpt2",
11
  device=-1
12
  ),
13
- "ruGPT3-Small": pipeline(
14
  "text-generation",
15
- model="ai-forever/rugpt3small_based_on_gpt2",
16
- tokenizer="ai-forever/rugpt3small_based_on_gpt2",
17
  device=-1
18
  ),
19
- "SambaLingo": pipeline(
20
  "text-generation",
21
- model="sambanovasystems/SambaLingo-Russian-Chat",
22
- tokenizer="sambanovasystems/SambaLingo-Russian-Chat",
23
  device=-1
24
  )
25
  }
26
 
27
- # Построение обычного промпта
28
  def build_simple_prompt(user_input):
29
  return f"Клиент: {user_input}\nКатегория обращения:"
30
 
31
- # Построение CoT-промпта
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=100, 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=60, 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,34 +65,37 @@ def generate_classification(user_input):
65
  }
66
 
67
  return (
68
- results["ruGPT3-Medium"]["cot_answer"], f"{results['ruGPT3-Medium"]["cot_time"]} сек",
69
- results["ruGPT3-Medium"]["simple_answer"], f"{results["ruGPT3-Medium"]["simple_time"]} сек",
70
- results["ruGPT3-Small"]["cot_answer"], f"{results["ruGPT3-Small"]["cot_time"]} сек",
71
- results["ruGPT3-Small"]["simple_answer"], f"{results["ruGPT3-Small"]["simple_time"]} сек",
72
- results["SambaLingo"]["cot_answer"], f"{results["SambaLingo"]["cot_time"]} сек",
73
- results["SambaLingo"]["simple_answer"], f"{results["SambaLingo"]["simple_time"]} сек"
74
  )
75
 
76
  # Gradio UI
77
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
78
- gr.Markdown("🏦 **Банковский помощник: CoT vs. Обычный ответ (магистерская работа)**")
79
 
80
- inp = gr.Textbox(label="Вопрос клиента", placeholder="Например: Я не могу перевести деньги на другую карту", lines=2)
81
  btn = gr.Button("Сгенерировать")
82
 
83
- gr.Markdown("### ruGPT3-Medium")
 
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
- gr.Markdown("### ruGPT3-Small")
 
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
- gr.Markdown("### SambaLingo-Russian-Chat")
 
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="Обычный ответ")