data-silence commited on
Commit
79fe0fe
1 Parent(s): 5c5e259

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +30 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +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})"
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ torch