ilushado commited on
Commit
1b02242
·
1 Parent(s): d4ef182

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -88,29 +88,35 @@ title = st.text_area("Title HERE")
88
  abstract = st.text_area("Abstract HERE")
89
 
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
- text = title + " : " + abstract
93
 
94
- inputs = tokenizer.encode_plus(
95
- text,
96
- None,
97
- add_special_tokens=True,
98
- max_length=256,
99
- pad_to_max_length=True,
100
- return_token_type_ids=True
101
- )
102
 
103
 
104
- ids = torch.Tensor(inputs['input_ids']).long()
105
- mask = torch.Tensor(inputs['attention_mask']).long()
106
- token_type_ids = torch.Tensor(inputs['token_type_ids']).long()
107
 
108
- ans = model(ids.unsqueeze(0), mask.unsqueeze(0), token_type_ids.unsqueeze(0))
109
 
110
 
111
  from transformers import pipeline
112
  # тут уже знакомый вам код с huggingface.transformers -- его можно заменить на что угодно от fairseq до catboost
113
 
 
114
  idx = torch.nn.functional.softmax(ans[0], dim=0).argmax().item()
115
  st.markdown(f'{idx_to_tag[idx]}')
116
  # выводим результаты модели в текстовое поле, на потеху пользователю
 
88
  abstract = st.text_area("Abstract HERE")
89
 
90
 
91
+ if st.button('Предположить'):
92
+ text = title + " : " + abstract
93
+ inputs = tokenizer.encode_plus(
94
+ text,
95
+ None,
96
+ add_special_tokens=True,
97
+ max_length=256,
98
+ pad_to_max_length=True,
99
+ return_token_type_ids=True
100
+ )
101
+
102
+
103
+ ids = torch.Tensor(inputs['input_ids']).long()
104
+ mask = torch.Tensor(inputs['attention_mask']).long()
105
+ token_type_ids = torch.Tensor(inputs['token_type_ids']).long()
106
+
107
+ ans = model(ids.unsqueeze(0), mask.unsqueeze(0), token_type_ids.unsqueeze(0))
108
+
109
 
 
110
 
 
 
 
 
 
 
 
 
111
 
112
 
 
 
 
113
 
 
114
 
115
 
116
  from transformers import pipeline
117
  # тут уже знакомый вам код с huggingface.transformers -- его можно заменить на что угодно от fairseq до catboost
118
 
119
+
120
  idx = torch.nn.functional.softmax(ans[0], dim=0).argmax().item()
121
  st.markdown(f'{idx_to_tag[idx]}')
122
  # выводим результаты модели в текстовое поле, на потеху пользователю