Djacon commited on
Commit
87e622a
Β·
1 Parent(s): 4a46b4a

merged two blocks

Browse files
.gitignore CHANGED
@@ -1,2 +1 @@
1
- __pycache__/
2
- copy.bat
 
1
+ __pycache__/
 
inference.py CHANGED
@@ -1,6 +1,6 @@
1
  import torch
2
- import requests
3
  from transformers import BertForSequenceClassification, AutoTokenizer
 
4
 
5
  # path_emo = 'Djacon/rubert-tiny2-russian-emotion-detection'
6
  path_emo = './models/emotion_detection/'
@@ -29,21 +29,16 @@ def predict_emotions(text: str) -> str:
29
  key=lambda x: -x[1]))
30
 
31
 
32
- def predict_summarization(text: str) -> str:
33
- url = "https://www.editpad.org/tool/tool/summarizingTool"
34
- headers = {"Content-Type": "application/x-www-form-urlencoded"}
35
-
36
- data = {"text": text, "modd": 1, "captha": 0, 'percnt': 10,
37
- "max-length": len(text) / 10}
38
 
39
- response = requests.post(url, headers=headers, data=data)
40
 
41
- if response.status_code != 200:
42
- return 'err'
43
-
44
- response_json = response.json()
45
- print(len(response_json.get('content')), len(text))
46
- return response_json.get("content", 'err')
47
 
48
 
49
  def test():
 
1
  import torch
 
2
  from transformers import BertForSequenceClassification, AutoTokenizer
3
+ from transformers import PegasusForConditionalGeneration, PegasusTokenizer
4
 
5
  # path_emo = 'Djacon/rubert-tiny2-russian-emotion-detection'
6
  path_emo = './models/emotion_detection/'
 
29
  key=lambda x: -x[1]))
30
 
31
 
32
+ path_sum = './models/summarizer/'
33
+ model_sum = PegasusForConditionalGeneration.from_pretrained(path_sum)
34
+ tokenizer_sum = PegasusTokenizer.from_pretrained(path_sum)
 
 
 
35
 
 
36
 
37
+ def predict_summarization(text: str) -> str:
38
+ batch = tokenizer_sum([text], truncation=True, padding="longest",
39
+ return_tensors="pt")
40
+ translated = model_sum.generate(**batch)
41
+ return tokenizer_sum.batch_decode(translated, skip_special_tokens=True)[0]
 
42
 
43
 
44
  def test():
models/summarizer/config.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "./",
3
+ "activation_dropout": 0.1,
4
+ "activation_function": "relu",
5
+ "add_bias_logits": false,
6
+ "add_final_layer_norm": true,
7
+ "architectures": [
8
+ "PegasusForConditionalGeneration"
9
+ ],
10
+ "attention_dropout": 0.1,
11
+ "bos_token_id": 0,
12
+ "classif_dropout": 0.0,
13
+ "classifier_dropout": 0.0,
14
+ "d_model": 1024,
15
+ "decoder_attention_heads": 16,
16
+ "decoder_ffn_dim": 4096,
17
+ "decoder_layerdrop": 0.0,
18
+ "decoder_layers": 16,
19
+ "decoder_start_token_id": 0,
20
+ "do_blenderbot_90_layernorm": false,
21
+ "dropout": 0.1,
22
+ "encoder_attention_heads": 16,
23
+ "encoder_ffn_dim": 4096,
24
+ "encoder_layerdrop": 0.0,
25
+ "encoder_layers": 16,
26
+ "eos_token_id": 1,
27
+ "extra_pos_embeddings": 0,
28
+ "force_bos_token_to_be_generated": false,
29
+ "forced_eos_token_id": 1,
30
+ "gradient_checkpointing": false,
31
+ "id2label": {
32
+ "0": "LABEL_0",
33
+ "1": "LABEL_1",
34
+ "2": "LABEL_2"
35
+ },
36
+ "init_std": 0.02,
37
+ "is_encoder_decoder": true,
38
+ "label2id": {
39
+ "LABEL_0": 0,
40
+ "LABEL_1": 1,
41
+ "LABEL_2": 2
42
+ },
43
+ "length_penalty": 0.6,
44
+ "max_length": 64,
45
+ "max_position_embeddings": 512,
46
+ "model_type": "pegasus",
47
+ "normalize_before": true,
48
+ "normalize_embedding": false,
49
+ "num_beams": 8,
50
+ "num_hidden_layers": 16,
51
+ "pad_token_id": 0,
52
+ "scale_embedding": true,
53
+ "static_position_embeddings": true,
54
+ "transformers_version": "4.11.0.dev0",
55
+ "use_cache": true,
56
+ "vocab_size": 96103
57
+ }
models/summarizer/generation_config.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 0,
4
+ "decoder_start_token_id": 0,
5
+ "eos_token_id": 1,
6
+ "forced_eos_token_id": 1,
7
+ "length_penalty": 0.6,
8
+ "max_length": 64,
9
+ "num_beams": 8,
10
+ "pad_token_id": 0,
11
+ "transformers_version": "4.27.0.dev0"
12
+ }
models/summarizer/pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f19169fbf6d5bf3b3c713cb933e40a5fa22ffdb6e0d7628309e2deabc5978e59
3
+ size 2275329241
models/summarizer/special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"eos_token": "</s>", "unk_token": "<unk>", "pad_token": "<pad>"}
models/summarizer/spiece.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0015189ef36359283fec8b93cf6d9ce51bca37eb1101defc68a53b394913b96c
3
+ size 1912529
models/summarizer/tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"model_max_length": 512, "special_tokens_map_file": null, "full_tokenizer_file": null}
static/emotion_detection.html CHANGED
@@ -226,9 +226,16 @@
226
 
227
  <div class="mt-6">
228
  <div class="w-full p-4 bg-white rounded-lg xl:p-6">
229
- <h1 class="text-lg font-medium text-gray-700 capitalize sm:text-xl md:text-2xl">Upload text</h1>
230
-
231
- <form id='sum-form' class="mt-6 space-y-5" onsubmit="return false;">
 
 
 
 
 
 
 
232
  <div id="sum-text-div">
233
  <textarea id="sum-text-input" required class="block w-full px-4 py-2.5 mt-2 text-gray-600 placeholder-gray-400 bg-white border border-gray-200 rounded-md focus:border-indigo-400 focus:outline-none focus:ring focus:ring-indigo-300 focus:ring-opacity-40"
234
  style="min-height: 250px;" placeholder="Enter or upload your text and press &quot;Detect&quot;"></textarea>
@@ -253,13 +260,9 @@
253
  Detect
254
  </button>
255
  </div>
256
- </form>
257
- </div>
258
-
259
- <div class="w-full p-4 mt-8 bg-white rounded-lg xl:p-6">
260
- <h1 class="text-lg font-medium text-gray-700 capitalize sm:text-xl md:text-2xl">Result</h1>
261
 
262
- <div class="md:flex gap-8">
263
  <div class="hidden w-full md:w-1/2 grid-cols-2 mt-6">
264
  <label for="description"
265
  class="block text-sm text-gray-700 capitalize">Extracted Text</label>
@@ -268,8 +271,6 @@
268
  </div>
269
 
270
  <div class="w-full md:w-1/2 grid-cols-2 mt-6">
271
- <label for="description"
272
- class="block text-sm text-gray-700 capitalize">Emotion Prediction</label>
273
  <textarea id="summarized-text"
274
  class="minh-text block w-full px-4 py-2.5 mt-2 text-gray-600 placeholder-gray-400 bg-white border border-gray-200 rounded-md focus:border-indigo-400 focus:outline-none focus:ring focus:ring-indigo-300 focus:ring-opacity-40"
275
  style="min-height: 250px;"></textarea>
 
226
 
227
  <div class="mt-6">
228
  <div class="w-full p-4 bg-white rounded-lg xl:p-6">
229
+ <ul class="flex text-sm text-center text-gray-500 divide-x divide-gray-200">
230
+ <li class="w-full">
231
+ <button id="show-original" class="bg-gray-100 inline-block w-full p-2 text-gray-900 focus:ring-4 focus:ring-blue-300 focus:outline-none">Original</button>
232
+ </li>
233
+ <li class="w-full">
234
+ <button id="show-summary" class="inline-block w-full p-2 hover:text-gray-700 hover:bg-gray-50 focus:ring-4 focus:ring-blue-300 focus:outline-none">Summary</button>
235
+ </li>
236
+ </ul>
237
+
238
+ <div id='sum-original' class="mt-6 space-y-5" onsubmit="return false;">
239
  <div id="sum-text-div">
240
  <textarea id="sum-text-input" required class="block w-full px-4 py-2.5 mt-2 text-gray-600 placeholder-gray-400 bg-white border border-gray-200 rounded-md focus:border-indigo-400 focus:outline-none focus:ring focus:ring-indigo-300 focus:ring-opacity-40"
241
  style="min-height: 250px;" placeholder="Enter or upload your text and press &quot;Detect&quot;"></textarea>
 
260
  Detect
261
  </button>
262
  </div>
263
+ </div>
 
 
 
 
264
 
265
+ <div id="sum-summary" class='hidden mt-6 space-y-5'>
266
  <div class="hidden w-full md:w-1/2 grid-cols-2 mt-6">
267
  <label for="description"
268
  class="block text-sm text-gray-700 capitalize">Extracted Text</label>
 
271
  </div>
272
 
273
  <div class="w-full md:w-1/2 grid-cols-2 mt-6">
 
 
274
  <textarea id="summarized-text"
275
  class="minh-text block w-full px-4 py-2.5 mt-2 text-gray-600 placeholder-gray-400 bg-white border border-gray-200 rounded-md focus:border-indigo-400 focus:outline-none focus:ring focus:ring-indigo-300 focus:ring-opacity-40"
276
  style="min-height: 250px;"></textarea>
static/js/detection.js CHANGED
@@ -1,7 +1,6 @@
1
  // Form Divs
2
- const form = document.getElementById('sum-form');
3
- const sumText = document.getElementById('sum-text-div');
4
- const sumFile = document.getElementById('sum-file-div')
5
 
6
  // Form Data
7
  const sumTextInput = document.getElementById('sum-text-input');
@@ -17,6 +16,12 @@ const summaryText = document.getElementById('summarized-text');
17
  // Word Counter
18
  const wordsCount = document.getElementById('word-counter');
19
 
 
 
 
 
 
 
20
  const MAX_SIZE = 20000;
21
 
22
 
@@ -87,6 +92,8 @@ async function summarize(event) {
87
 
88
  sumError.classList.add('hidden');
89
 
 
 
90
  // Here we can finally summarize data
91
  summaryText.value = 'Please wait...';
92
  extractText.value = sumTextInput.value.trim().slice(0, MAX_SIZE);
@@ -106,6 +113,22 @@ function _update_counter() {
106
  wordsCount.innerHTML = `Words: ${text.split(/\s+/).length} | Chars: ${text.length}`
107
  }
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  document.addEventListener('DOMContentLoaded', function () {
110
  var submitButton = document.getElementById('submit');
111
  submitButton.addEventListener('click', summarize);
@@ -133,4 +156,7 @@ document.addEventListener('DOMContentLoaded', function () {
133
  });
134
 
135
  sumTextInput.addEventListener('input', _update_counter);
 
 
 
136
  });
 
1
  // Form Divs
2
+ const sumText = document.getElementById('sum-text-div');
3
+ const sumFile = document.getElementById('sum-file-div')
 
4
 
5
  // Form Data
6
  const sumTextInput = document.getElementById('sum-text-input');
 
16
  // Word Counter
17
  const wordsCount = document.getElementById('word-counter');
18
 
19
+ // Tabs
20
+ const original = document.getElementById('sum-original');
21
+ const summary = document.getElementById('sum-summary');
22
+ const showOriginal = document.getElementById('show-original');
23
+ const showSummary = document.getElementById('show-summary');
24
+
25
  const MAX_SIZE = 20000;
26
 
27
 
 
92
 
93
  sumError.classList.add('hidden');
94
 
95
+ _show_summary();
96
+
97
  // Here we can finally summarize data
98
  summaryText.value = 'Please wait...';
99
  extractText.value = sumTextInput.value.trim().slice(0, MAX_SIZE);
 
113
  wordsCount.innerHTML = `Words: ${text.split(/\s+/).length} | Chars: ${text.length}`
114
  }
115
 
116
+ function _show_summary() {
117
+ showOriginal.classList.remove('bg-gray-100');
118
+ showSummary.classList.add('bg-gray-100');
119
+
120
+ summary.classList.remove('hidden');
121
+ original.classList.add('hidden');
122
+ }
123
+
124
+ function _show_original() {
125
+ showOriginal.classList.add('bg-gray-100');
126
+ showSummary.classList.remove('bg-gray-100');
127
+
128
+ original.classList.remove('hidden');
129
+ summary.classList.add('hidden');
130
+ }
131
+
132
  document.addEventListener('DOMContentLoaded', function () {
133
  var submitButton = document.getElementById('submit');
134
  submitButton.addEventListener('click', summarize);
 
156
  });
157
 
158
  sumTextInput.addEventListener('input', _update_counter);
159
+
160
+ showSummary.addEventListener('click', _show_summary);
161
+ showOriginal.addEventListener('click', _show_original);
162
  });
static/js/summarizer.js CHANGED
@@ -1,5 +1,4 @@
1
  // Form Divs
2
- const form = document.getElementById('sum-form');
3
  const sumText = document.getElementById('sum-text-div');
4
  const sumFile = document.getElementById('sum-file-div')
5
  const sumVideo = document.getElementById('sum-video-div');
@@ -20,6 +19,12 @@ const summaryText = document.getElementById('summarized-text');
20
  // Word Counter
21
  const wordsCount = document.getElementById('word-counter');
22
 
 
 
 
 
 
 
23
  const MAX_SIZE = 20000;
24
 
25
 
@@ -34,10 +39,11 @@ function _summarize() {
34
  if (xhr.readyState === 4 && xhr.status === 200) {
35
  result = xhr.responseText.split('\\n').join('\n');
36
  summaryText.value = result.slice(1, -1);
 
37
  }
38
  };
39
 
40
- xhr.send(data)
41
  return;
42
  }
43
 
@@ -102,6 +108,8 @@ async function summarize(event) {
102
 
103
  sumError.classList.add('hidden');
104
 
 
 
105
  // Here we can finally summarize data
106
  summaryText.value = 'Please wait...';
107
  switch (selectOption.value) {
@@ -150,6 +158,23 @@ function _update_counter() {
150
  }
151
 
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  document.addEventListener('DOMContentLoaded', function () {
154
  selectOption.addEventListener('change', _update_option);
155
 
@@ -182,4 +207,7 @@ document.addEventListener('DOMContentLoaded', function () {
182
  });
183
 
184
  sumTextInput.addEventListener('input', _update_counter);
 
 
 
185
  });
 
1
  // Form Divs
 
2
  const sumText = document.getElementById('sum-text-div');
3
  const sumFile = document.getElementById('sum-file-div')
4
  const sumVideo = document.getElementById('sum-video-div');
 
19
  // Word Counter
20
  const wordsCount = document.getElementById('word-counter');
21
 
22
+ // Tabs
23
+ const original = document.getElementById('sum-original');
24
+ const summary = document.getElementById('sum-summary');
25
+ const showOriginal = document.getElementById('show-original');
26
+ const showSummary = document.getElementById('show-summary');
27
+
28
  const MAX_SIZE = 20000;
29
 
30
 
 
39
  if (xhr.readyState === 4 && xhr.status === 200) {
40
  result = xhr.responseText.split('\\n').join('\n');
41
  summaryText.value = result.slice(1, -1);
42
+ _show_summary();
43
  }
44
  };
45
 
46
+ xhr.send(data);
47
  return;
48
  }
49
 
 
108
 
109
  sumError.classList.add('hidden');
110
 
111
+ _show_summary();
112
+
113
  // Here we can finally summarize data
114
  summaryText.value = 'Please wait...';
115
  switch (selectOption.value) {
 
158
  }
159
 
160
 
161
+ function _show_summary() {
162
+ showOriginal.classList.remove('bg-gray-100');
163
+ showSummary.classList.add('bg-gray-100');
164
+
165
+ summary.classList.remove('hidden');
166
+ original.classList.add('hidden');
167
+ }
168
+
169
+ function _show_original() {
170
+ showOriginal.classList.add('bg-gray-100');
171
+ showSummary.classList.remove('bg-gray-100');
172
+
173
+ original.classList.remove('hidden');
174
+ summary.classList.add('hidden');
175
+ }
176
+
177
+
178
  document.addEventListener('DOMContentLoaded', function () {
179
  selectOption.addEventListener('change', _update_option);
180
 
 
207
  });
208
 
209
  sumTextInput.addEventListener('input', _update_counter);
210
+
211
+ showSummary.addEventListener('click', _show_summary);
212
+ showOriginal.addEventListener('click', _show_original);
213
  });
static/text_summarizer.html CHANGED
@@ -225,10 +225,17 @@
225
  </div>
226
 
227
  <div class="mt-6">
228
- <div class="w-full p-4 bg-white rounded-lg xl:p-6">
229
- <h1 class="text-lg font-medium text-gray-700 capitalize sm:text-xl md:text-2xl">Upload text</h1>
230
-
231
- <form id='sum-form' class="mt-6 space-y-5" onsubmit="return false;">
 
 
 
 
 
 
 
232
  <div>
233
  <label for="sum-type" class="block text-sm text-gray-700 capitalize">Select Type</label>
234
  <select id="sum-type"
@@ -270,13 +277,9 @@
270
  Summarize
271
  </button>
272
  </div>
273
- </form>
274
- </div>
275
-
276
- <div class="w-full p-4 mt-8 bg-white rounded-lg xl:p-6">
277
- <h1 class="text-lg font-medium text-gray-700 capitalize sm:text-xl md:text-2xl">Result</h1>
278
 
279
- <div class="md:flex gap-8">
280
  <div class="w-full md:w-1/2 grid-cols-2 mt-6 hidden">
281
  <label for="description"
282
  class="block text-sm text-gray-700 capitalize">Extracted Text</label>
@@ -285,8 +288,6 @@
285
  </div>
286
 
287
  <div class="w-full md:w-1/2 grid-cols-2 mt-6">
288
- <label for="description"
289
- class="block text-sm text-gray-700 capitalize">Summarized Text</label>
290
  <textarea id="summarized-text"
291
  class="minh-text block w-full px-4 py-2.5 mt-2 text-gray-600 placeholder-gray-400 bg-white border border-gray-200 rounded-md focus:border-indigo-400 focus:outline-none focus:ring focus:ring-indigo-300 focus:ring-opacity-40"
292
  style="min-height: 250px;"></textarea>
 
225
  </div>
226
 
227
  <div class="mt-6">
228
+ <div class="w-full p-4 bg-white xl:p-6">
229
+ <ul class="flex text-sm text-center text-gray-500 divide-x divide-gray-200">
230
+ <li class="w-full">
231
+ <button id="show-original" class="bg-gray-100 inline-block w-full p-2 text-gray-900 focus:ring-4 focus:ring-blue-300 focus:outline-none">Original</button>
232
+ </li>
233
+ <li class="w-full">
234
+ <button id="show-summary" class="inline-block w-full p-2 hover:text-gray-700 hover:bg-gray-50 focus:ring-4 focus:ring-blue-300 focus:outline-none">Summary</button>
235
+ </li>
236
+ </ul>
237
+
238
+ <div id='sum-original' class="mt-6 space-y-5">
239
  <div>
240
  <label for="sum-type" class="block text-sm text-gray-700 capitalize">Select Type</label>
241
  <select id="sum-type"
 
277
  Summarize
278
  </button>
279
  </div>
280
+ </div>
 
 
 
 
281
 
282
+ <div id="sum-summary" class='hidden mt-6 space-y-5'>
283
  <div class="w-full md:w-1/2 grid-cols-2 mt-6 hidden">
284
  <label for="description"
285
  class="block text-sm text-gray-700 capitalize">Extracted Text</label>
 
288
  </div>
289
 
290
  <div class="w-full md:w-1/2 grid-cols-2 mt-6">
 
 
291
  <textarea id="summarized-text"
292
  class="minh-text block w-full px-4 py-2.5 mt-2 text-gray-600 placeholder-gray-400 bg-white border border-gray-200 rounded-md focus:border-indigo-400 focus:outline-none focus:ring focus:ring-indigo-300 focus:ring-opacity-40"
293
  style="min-height: 250px;"></textarea>