Djacon commited on
Commit
6c4629b
Β·
1 Parent(s): d6477ed

Add Caching

Browse files
extract.py CHANGED
@@ -54,7 +54,7 @@ def get_pagerank(importance, top_k):
54
 
55
 
56
  def summarize_text(text: str) -> str:
57
- return 'сыр'
58
  sentences = sent_tokenize(text)[:2000]
59
  top_k = max(20, int(len(sentences) ** .5))
60
  mat = build_matrix(sentences)
 
54
 
55
 
56
  def summarize_text(text: str) -> str:
57
+ return text
58
  sentences = sent_tokenize(text)[:2000]
59
  top_k = max(20, int(len(sentences) ** .5))
60
  mat = build_matrix(sentences)
files/js/detection.js CHANGED
@@ -25,7 +25,13 @@ const showSummary = document.getElementById('show-summary');
25
  const MAX_SIZE = 20000;
26
 
27
 
28
- function _detect() {
 
 
 
 
 
 
29
  var xhr = new XMLHttpRequest();
30
  xhr.open('POST', '/predict_emotion', true);
31
  xhr.setRequestHeader('Content-Type', 'application/json');
@@ -36,6 +42,10 @@ function _detect() {
36
  if (xhr.readyState === 4 && xhr.status === 200) {
37
  result = xhr.responseText.split('\\n').join('\n');
38
  summaryText.value = result.slice(1, -1);
 
 
 
 
39
  }
40
  };
41
 
@@ -94,6 +104,12 @@ async function summarize(event) {
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);
 
25
  const MAX_SIZE = 20000;
26
 
27
 
28
+ let cache = {
29
+ 'text': undefined,
30
+ 'result': undefined,
31
+ }
32
+
33
+
34
+ async function _detect() {
35
  var xhr = new XMLHttpRequest();
36
  xhr.open('POST', '/predict_emotion', true);
37
  xhr.setRequestHeader('Content-Type', 'application/json');
 
42
  if (xhr.readyState === 4 && xhr.status === 200) {
43
  result = xhr.responseText.split('\\n').join('\n');
44
  summaryText.value = result.slice(1, -1);
45
+ cache = {
46
+ 'text': extractText.value,
47
+ 'result': summaryText.value
48
+ };
49
  }
50
  };
51
 
 
104
 
105
  _show_summary();
106
 
107
+ if (value === cache.text) {
108
+ console.log('Result already in cache!');
109
+ summaryText.value = cache.result;
110
+ return;
111
+ }
112
+
113
  // Here we can finally summarize data
114
  summaryText.value = 'Please wait...';
115
  extractText.value = sumTextInput.value.trim().slice(0, MAX_SIZE);
files/js/grammar.js CHANGED
@@ -25,6 +25,12 @@ const showSummary = document.getElementById('show-summary');
25
  const MAX_SIZE = 20000;
26
 
27
 
 
 
 
 
 
 
28
  function _check() {
29
  var xhr = new XMLHttpRequest();
30
  xhr.open('POST', '/predict_grammar', true);
@@ -36,6 +42,10 @@ function _check() {
36
  if (xhr.readyState === 4 && xhr.status === 200) {
37
  result = xhr.responseText.split('\\n').join('\n');
38
  summaryText.value = result.slice(1, -1);
 
 
 
 
39
  }
40
  };
41
 
@@ -94,6 +104,12 @@ async function summarize(event) {
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);
@@ -183,4 +199,4 @@ document.addEventListener('DOMContentLoaded', function () {
183
  showOriginal.addEventListener('click', _show_original);
184
  });
185
 
186
- summaryText.placeholder = `Acceptance: 0.50`;
 
25
  const MAX_SIZE = 20000;
26
 
27
 
28
+ let cache = {
29
+ 'text': undefined,
30
+ 'result': undefined,
31
+ }
32
+
33
+
34
  function _check() {
35
  var xhr = new XMLHttpRequest();
36
  xhr.open('POST', '/predict_grammar', true);
 
42
  if (xhr.readyState === 4 && xhr.status === 200) {
43
  result = xhr.responseText.split('\\n').join('\n');
44
  summaryText.value = result.slice(1, -1);
45
+ cache = {
46
+ 'text': extractText.value,
47
+ 'result': summaryText.value
48
+ };
49
  }
50
  };
51
 
 
104
 
105
  _show_summary();
106
 
107
+ if (value === cache.text) {
108
+ console.log('Result already in cache!');
109
+ summaryText.value = cache.result;
110
+ return;
111
+ }
112
+
113
  // Here we can finally summarize data
114
  summaryText.value = 'Please wait...';
115
  extractText.value = sumTextInput.value.trim().slice(0, MAX_SIZE);
 
199
  showOriginal.addEventListener('click', _show_original);
200
  });
201
 
202
+ summaryText.placeholder = `Acceptance: 50.00%`;
files/js/summarizer.js CHANGED
@@ -28,6 +28,12 @@ const showSummary = document.getElementById('show-summary');
28
  const MAX_SIZE = 100000;
29
 
30
 
 
 
 
 
 
 
31
  function _summarize() {
32
  var xhr = new XMLHttpRequest();
33
  xhr.open('POST', '/predict_summarization', true);
@@ -39,7 +45,10 @@ function _summarize() {
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
 
@@ -120,6 +129,13 @@ async function summarize(event) {
120
  extractText.value = sumVideoInput.value.slice(0, MAX_SIZE);
121
  break;
122
  }
 
 
 
 
 
 
 
123
  _summarize();
124
  }
125
 
 
28
  const MAX_SIZE = 100000;
29
 
30
 
31
+ let cache = {
32
+ 'text': undefined,
33
+ 'result': undefined,
34
+ }
35
+
36
+
37
  function _summarize() {
38
  var xhr = new XMLHttpRequest();
39
  xhr.open('POST', '/predict_summarization', true);
 
45
  if (xhr.readyState === 4 && xhr.status === 200) {
46
  result = xhr.responseText.split('\\n').join('\n');
47
  summaryText.value = result.slice(1, -1);
48
+ cache = {
49
+ 'text': extractText.value,
50
+ 'result': summaryText.value
51
+ };
52
  }
53
  };
54
 
 
129
  extractText.value = sumVideoInput.value.slice(0, MAX_SIZE);
130
  break;
131
  }
132
+
133
+ if (extractText.value === cache.text) {
134
+ console.log('Result already in cache!');
135
+ summaryText.value = cache.result;
136
+ return;
137
+ }
138
+
139
  _summarize();
140
  }
141