data-silence commited on
Commit
8380ce4
1 Parent(s): d6ecd3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -29
app.py CHANGED
@@ -1,30 +1,30 @@
1
- from transformers import pipeline
2
-
3
- # Загрузка модели через pipeline
4
- classifier = pipeline("text-classification", model="data-silence/news_classifier")
5
-
6
- # Словарь для преобразования меток
7
- category_mapper = {
8
- 'LABEL_0': 'climate',
9
- 'LABEL_1': 'conflicts',
10
- 'LABEL_2': 'culture',
11
- 'LABEL_3': 'economy',
12
- 'LABEL_4': 'gloss',
13
- 'LABEL_5': 'health',
14
- 'LABEL_6': 'politics',
15
- 'LABEL_7': 'science',
16
- 'LABEL_8': 'society',
17
- 'LABEL_9': 'sports',
18
- 'LABEL_10': 'travel'
19
- }
20
-
21
- def classify(text):
22
- result = classifier(text)
23
- category = category_mapper[result[0]['label']]
24
- score = result[0]['score']
25
- return {"category": category, "confidence": score}
26
-
27
- # Для Gradio интерфейса
28
- def run_inference(text):
29
- result = classify(text)
30
  return f"Predicted category: {result['category']} (confidence: {result['confidence']:.2f})"
 
1
+ from transformers import pipeline
2
+
3
+ # Загрузка модели через pipeline
4
+ classifier = pipeline("text-classification", model="data-silence/news_classifier_ft")
5
+
6
+ # Словарь для преобразования меток
7
+ category_mapper = {
8
+ 'LABEL_0': 'climate',
9
+ 'LABEL_1': 'conflicts',
10
+ 'LABEL_2': 'culture',
11
+ 'LABEL_3': 'economy',
12
+ 'LABEL_4': 'gloss',
13
+ 'LABEL_5': 'health',
14
+ 'LABEL_6': 'politics',
15
+ 'LABEL_7': 'science',
16
+ 'LABEL_8': 'society',
17
+ 'LABEL_9': 'sports',
18
+ 'LABEL_10': 'travel'
19
+ }
20
+
21
+ def classify(text):
22
+ result = classifier(text)
23
+ category = category_mapper[result[0]['label']]
24
+ score = result[0]['score']
25
+ return {"category": category, "confidence": score}
26
+
27
+ # Для Gradio интерфейса
28
+ def run_inference(text):
29
+ result = classify(text)
30
  return f"Predicted category: {result['category']} (confidence: {result['confidence']:.2f})"