marry1908 commited on
Commit
31550e9
·
verified ·
1 Parent(s): 7147b26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -3,6 +3,7 @@ from transformers import pipeline
3
  import time
4
  import pandas as pd
5
  from datetime import datetime
 
6
 
7
  # Загружаем модель для тематической классификации
8
  # Используем zero-shot классификатор, который не требует предобучения на конкретных темах
@@ -63,12 +64,16 @@ def classify_topic(text, show_top_n=3):
63
  # Форматируем результаты
64
  output_text = f"📊 **Тематическая классификация:**\n\n"
65
 
66
- # Берем топ-N результатов
67
- top_indices = results['scores'].argsort()[-show_top_n:][::-1]
 
68
 
69
- for i, idx in enumerate(top_indices, 1):
70
- topic = results['labels'][idx]
71
- score = results['scores'][idx] * 100
 
 
 
72
  description = TOPIC_DESCRIPTIONS.get(topic, topic)
73
 
74
  # Прогресс-бар
@@ -83,12 +88,12 @@ def classify_topic(text, show_top_n=3):
83
 
84
  # Сохраняем в историю
85
  timestamp = datetime.now().strftime("%H:%M:%S")
86
- top_topic = results['labels'][top_indices[0]]
87
  history.insert(0, {
88
  'time': timestamp,
89
  'text': text[:50] + ("..." if len(text) > 50 else ""),
90
  'topic': TOPIC_DESCRIPTIONS.get(top_topic, top_topic),
91
- 'confidence': f"{results['scores'][top_indices[0]]*100:.1f}%"
92
  })
93
 
94
  # Ограничиваем историю
 
3
  import time
4
  import pandas as pd
5
  from datetime import datetime
6
+ import numpy as np
7
 
8
  # Загружаем модель для тематической классификации
9
  # Используем zero-shot классификатор, который не требует предобучения на конкретных темах
 
64
  # Форматируем результаты
65
  output_text = f"📊 **Тематическая классификация:**\n\n"
66
 
67
+ # Получаем списки тем и оценок
68
+ labels = results['labels']
69
+ scores = results['scores']
70
 
71
+ # Сортируем по убыванию оценок и берем топ-N
72
+ sorted_indices = np.argsort(scores)[::-1][:show_top_n]
73
+
74
+ for i, idx in enumerate(sorted_indices, 1):
75
+ topic = labels[idx]
76
+ score = scores[idx] * 100
77
  description = TOPIC_DESCRIPTIONS.get(topic, topic)
78
 
79
  # Прогресс-бар
 
88
 
89
  # Сохраняем в историю
90
  timestamp = datetime.now().strftime("%H:%M:%S")
91
+ top_topic = labels[sorted_indices[0]]
92
  history.insert(0, {
93
  'time': timestamp,
94
  'text': text[:50] + ("..." if len(text) > 50 else ""),
95
  'topic': TOPIC_DESCRIPTIONS.get(top_topic, top_topic),
96
+ 'confidence': f"{scores[sorted_indices[0]]*100:.1f}%"
97
  })
98
 
99
  # Ограничиваем историю