Valeriy Sinyukov commited on
Commit
ce0c8db
·
1 Parent(s): 8670c25

Pretty print results

Browse files
Files changed (2) hide show
  1. app.py +5 -2
  2. results.py +121 -0
app.py CHANGED
@@ -1,8 +1,10 @@
 
1
  import streamlit as st
2
 
3
  from category_classification.models import models as class_models
4
  from common import Input
5
  from languages import *
 
6
 
7
  page_title = {en: "Papers classification", ru: "Классификация статей"}
8
  model_label = {en: "Select model", ru: "Выберете модель"}
@@ -33,5 +35,6 @@ abstract = st.text_area(abstract_label[lang], height=text_area_height(5))
33
  if title:
34
  input = Input(title=title, abstract=abstract, authors=authors)
35
  model = load_class_model(model_name)
36
- out = model(input)
37
- st.json(out)
 
 
1
+ import pandas as pd
2
  import streamlit as st
3
 
4
  from category_classification.models import models as class_models
5
  from common import Input
6
  from languages import *
7
+ from results import process_results
8
 
9
  page_title = {en: "Papers classification", ru: "Классификация статей"}
10
  model_label = {en: "Select model", ru: "Выберете модель"}
 
35
  if title:
36
  input = Input(title=title, abstract=abstract, authors=authors)
37
  model = load_class_model(model_name)
38
+ results = model(input)
39
+ results = process_results(results, lang)
40
+ st.dataframe(results)
results.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+ from languages import en, ru
4
+
5
+
6
+ def filter_results(results):
7
+ return results
8
+
9
+
10
+ category_init = "label"
11
+ certainty_init = "score"
12
+
13
+
14
+ def process_keys(results: pd.DataFrame, lang):
15
+ category = {en: "Category", ru: "Категория"}
16
+ certainty = {en: "Certainty", ru: "Уверенность"}
17
+ results = results.rename(
18
+ columns={
19
+ category_init: category.get(lang, category[en]),
20
+ certainty_init: certainty.get(lang, certainty[en]),
21
+ }
22
+ )
23
+ return results
24
+
25
+
26
+ def process_categories(results, lang):
27
+ categories = {
28
+ en: {
29
+ "math": "Math",
30
+ "astro-ph": "Astrophysics",
31
+ "cond-mat": "Condensed matter physics",
32
+ "hep-ph": "High energy physics -- Phenomenology",
33
+ "physics": "Physics",
34
+ "hep-th": "High energy physics -- Theory",
35
+ "cs": "Computer Science",
36
+ "quant-ph": "Quantum physics",
37
+ "gr-qc": "General Relativity and Quantum Cosmology",
38
+ "math-ph": "Mathematical Physics",
39
+ "nucl-th": "Nuclear Theory",
40
+ "eess": "Electrical Engineering and Systems Science",
41
+ "q-bio": "Quantitative Biology",
42
+ "nlin": "Nonlinear Sciences",
43
+ "stat": "Statistics",
44
+ "hep-lat": "High Energy Physics - Lattice",
45
+ "hep-ex": "High Energy Physics - Experiment",
46
+ "nucl-ex": "Nuclear Experiment",
47
+ "econ": "Economins",
48
+ "q-alg": "Quantum Algebra",
49
+ "q-fin": "Quantitative Finance",
50
+ "alg-geom": "Algebraic Geometry",
51
+ "supr-con": "Superconductivity",
52
+ "chao-dyn": "Chaotic dynamics",
53
+ "dg-ga": "Differential Geometry",
54
+ "funct-an": "Functional analysis",
55
+ "atom-ph": "Atomic physics",
56
+ "chem-ph": "Chemical Physics",
57
+ "ao-sci": "Atmospheric and Oceanic Physics",
58
+ "acc-phys": "Accelerator Physics",
59
+ "bayes-an": "Bayesian statistics",
60
+ "plasm-ph": "Plasma Physics",
61
+ },
62
+ ru: {
63
+ "math": "Математика",
64
+ "astro-ph": "Астрофизика",
65
+ "cond-mat": "Физика конденсированного состояния",
66
+ "hep-ph": "Физика элементарных частиц -- Феноменология",
67
+ "physics": "Физика",
68
+ "hep-th": "Физика элементарных частиц -- Теория",
69
+ "cs": "Компьютерные науки",
70
+ "quant-ph": "Квантовая физика",
71
+ "gr-qc": "Общая теория относительности и квантовая космология",
72
+ "math-ph": "Математическая физика",
73
+ "nucl-th": "Ядерная физика",
74
+ "eess": "Электротехника и системоведение",
75
+ "q-bio": "Количественная биология",
76
+ "nlin": "Нелинейные науки",
77
+ "stat": "Статистика",
78
+ "hep-lat": "Физика элементарных частиц -- Решетки",
79
+ "hep-ex": "Экспериментальная физика элементарных частиц",
80
+ "nucl-ex": "Ядерный эксперимент",
81
+ "econ": "Экономика",
82
+ "q-alg": "Квантовая алгебра",
83
+ "q-fin": "Количественные финансы",
84
+ "alg-geom": "Алгебраическая геометрия",
85
+ "supr-con": "Сверхпроводимость",
86
+ "chao-dyn": "Теория хаоса",
87
+ "dg-ga": "Дифференциальная геометрия",
88
+ "funct-an": "Функциональный анализ",
89
+ "atom-ph": "Атомная физика",
90
+ "chem-ph": "Химическая физика",
91
+ "ao-sci": "Физика атмосферы и океана",
92
+ "acc-phys": "Физика ускорителей",
93
+ "bayes-an": "Байесовская статистика",
94
+ "plasm-ph": "Физика плазмы",
95
+ },
96
+ }
97
+
98
+ def process_category(category):
99
+ if "." in category:
100
+ category = category[: category.index(".")]
101
+ return categories.get(lang, {}).get(category, category)
102
+
103
+ results[category_init] = results[category_init].apply(process_category)
104
+ return results
105
+
106
+
107
+ def process_certainities(results):
108
+ results[certainty_init] = results[certainty_init].apply(
109
+ lambda certainty: "{0:0.2f}%".format(100 * certainty)
110
+ )
111
+ return results
112
+
113
+
114
+ def process_results(results, lang):
115
+ results = pd.DataFrame(results)
116
+ results = results.sort_values(by=[certainty_init])
117
+ results = filter_results(results)
118
+ results = process_categories(results, lang)
119
+ results = process_certainities(results)
120
+ results = process_keys(results, lang)
121
+ return results