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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -21
app.py CHANGED
@@ -2,29 +2,29 @@ import gradio as gr
2
  import time
3
  from transformers import pipeline
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
 
@@ -33,13 +33,13 @@ 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)
@@ -47,12 +47,12 @@ def generate_classification(user_input):
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
- # Обычный ответ
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)
@@ -73,15 +73,15 @@ def generate_classification(user_input):
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="Обычный ответ")
@@ -95,7 +95,7 @@ with gr.Blocks() as demo:
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="Обычный ответ")
@@ -108,5 +108,3 @@ with gr.Blocks() as demo:
108
  ])
109
 
110
  demo.launch()
111
-
112
-
 
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(
14
  "text-generation",
15
+ model="deepseek-ai/DeepSeek-Coder-1.3B-instruct",
16
+ tokenizer="deepseek-ai/DeepSeek-Coder-1.3B-instruct",
17
  device=-1
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
 
 
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)
 
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)
 
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="Обычный ответ")
 
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="Обычный ответ")
 
108
  ])
109
 
110
  demo.launch()