File size: 10,788 Bytes
d0ed3d4
 
 
 
9573ed1
d0ed3d4
 
3ee4378
d0ed3d4
d0332aa
 
d0ed3d4
5088720
d0ed3d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!doctype html>
<html lang="en" class="js">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1">
    <meta name="description" content="summary is a small web application that help users summarizing long documents.">
    <title>summary</title>
    <link href="/embed/datien228/text-summarizer/static/assets/favicon.png" rel="icon" type="image/png" sizes="16x16">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
    <link rel="stylesheet" href="/embed/datien228/text-summarizer/static/css/style.css">
    <link rel="stylesheet" href="/embed/datien228/text-summarizer/static/assets/css/all.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.2/iframeResizer.contentWindow.min.js"></script>
  </head>
  <body class="d-flex flex-column min-vh-100">
      <ul class="nav nav-tabs">
        <li><a href="#" class="link link--io">creator</a></li>
        <li><a href="#" class="link link--io">development</a></li>
        <li><a href="#" class="link link--io">feedback</a></li>
      </ul>
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-12 my-4">
            <a href="{{ url_for('home') }}" class="link-title">
              <h1 class="text-center page-title">
                summary
              </h1>
            </a>
          </div>
        </div>
        <div class="row mt-4">
          <div class="col-md-1"></div>
          <div class="col-md-4 input-field">
            <div class="row mb-4 flex-col-50">
              <div class="col-md-8">
                <h2 class="main-heading">
                  put your text here
                </h2>
                <p>You can change document's language</p>
              </div>
              <div class="col-md-4 switch-format">
                <div class="toggle">
                  <input type="radio" name="langSel" value="eng" id="engLang" checked="checked" />
                  <label for="engLang">eng</label>
                  <input type="radio" name="langSel" value="vie" id="vieLang" />
                  <label for="vieLang">vie</label>
                </div>
              </div>
            </div>
            <div class="row mb-4">
              <div class="col-md-12">
                <form id="input_form" class="form-horizontal requires-validation" method="post" novalidate>
                  <textarea type="text" class="input-nlp-text form-control shadow-none" id="input_text" name="input_text"
                  placeholder="Enter the documents here >" aria-label="Input Document" required value="@Request["inputText"]"></textarea> 
                  <!-- <div class="valid-feedback">
                    Text looks good!
                 </div>
                 <div class="invalid-feedback">
                    Text is required!
                 </div>-->
                </form>
              </div>
            </div>
            <div class="row text-white" id="metadata">
              <div class="col-md-3 bg-black text-center flex-col" id="cnt-paras">
                 <p>0 par</p>
              </div>
              <div class="col-md-3 bg-black text-center flex-col" id="cnt-words">
                <p>0 word</p>
              </div>
              <div class="col-md-3 bg-black text-center flex-col" id="cnt-chars">
                <p>0 char</p>
              </div>
              <div class="col-md-3 bg-black text-center flex-col">
                <p>english</p>
              </div>
            </div>
          </div>
          <div class="spacer"></div>
          <div class="col-md-2 text-center my-auto">
            <div class="d-flex flex-column justify-content-center">
              <!-- <i class="fa-2x fa-solid fa-circle-check progress-icon" hidden></i> -->
              <input class="toggle-load-icon" type="checkbox" id="check" disabled>
              <label class="progress-icon" for="check" style="display:none">
                 <div class="check-icon"></div>
              </label>
              <button class="button summarize-button" type="submit" form="input_form">
                summarize
                <div class="button__horizontal"></div>
                <div class="button__vertical"></div>
              </button>
            </div>
            <h2 class="mt-2 pt-2" id="load-noti" style="display:none">Generating</h2>
          </div>
          <div class="spacer"></div>
          <div class="col-md-4 output-field">
            <div class="row mb-4 flex-col-50">
              <div class="col-md-8">
                <h2 class="main-heading">
                  summary here
                </h2>
                <p>You can change summary's length</p>
              </div>
              <div class="col-md-4 switch-format">
                <div class="toggle">
                  <input type="radio" name="lengSel" value="short" id="shortSum" checked="checked" />
                  <label for="shortSum">short</label>
                  <input type="radio" name="lengSel" value="long" id="longSum" />
                  <label for="longSum">long</label>
                </div>
                <!-- <button type="button" class="floated btn btn-outline-dark btn-sm btn-block" id="short_button">short</button>
                <button type="button" class="floated btn btn-outline-dark btn-sm btn-block" id="long_button">long</button> -->
                <!-- <button class="btn btn-outline-dark btn-sm"><i class="fa-solid fa-2xs">Expand</i></button> -->
              </div>
            </div>
            <div class="row mb-4">
              <div class="col-md-12">
                <textarea type="text" class="output-nlp-text no-border shadow-none" id="output_text"
                placeholder="Output will be shown here >" aria-label="Output Document" disabled></textarea> 
              </div>
            </div>
          </div>
          <div class="col-md-1"></div>
        </div>
      </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
    <script>
      // ======= INPUT FIELD (FORM CONTROL) VALIDATION =======
      var runOnce = false;
      var short_summary = '';
      var long_summary = '';

      (function () {
        'use strict'
        const forms = document.querySelectorAll('.requires-validation')
        Array.from(forms)
          .forEach(function (form) {
            form.addEventListener('submit', function (event) {
              if (!form.checkValidity()) {
                event.preventDefault()
                event.stopPropagation()
              }
              form.classList.add('was-validated')
            }, false)
          })
      })()

      // ======= RESET INPUT FIELD WHEN USER CLICKED AT IT (HAS RAN ONCE) =======
      $(function () {
        $('#input_text').on("input", function () {
          if (runOnce == true) {
            $(".progress-icon").hide();
            $("#load-noti").hide();
            $(".summarize-button").fadeIn();
          }
        });
      });

      $('#shortSum').on("click", function () {
        var outputField = document.getElementById("output_text");
        outputField.innerHTML = short_summary;
      });
      $('#longSum').on("click", function () {
        var outputField = document.getElementById("output_text");
        outputField.innerHTML = long_summary;
      });

      setInterval(function (e) {
        var strText = jQuery.trim($('#input_text').val());
        var cntChar = strText.replace( /[\r\n]+/gm, "" ).length;
        var cntWord = strText.split(/[\s\.\?]+/).length;
        var cntPara = strText.split("\n\n").length;
        var cntPara2 = strText.split("/\n\s/g").length;
        var postFix = '';

        if (strText == '') {
          cntWord = 0;
          cntLine = 0;
          cntPara = 0;
        }

        $('#cnt-paras').children('p').text(cntPara + (cntPara > 1 ? " pars" : " par"));
        $('#cnt-words').children('p').text(cntWord + (cntWord > 1 ? " words" : " word"));
        $('#cnt-chars').children('p').text(cntChar + (cntChar > 1 ? " chars" : " char"));
      }, 100);

      // ======= COMMUNICATE WITH FLSAK BACK END TO RUN ML TASK =======
      $(document).on('submit', '#input_form', function (e) {
        var outputField = document.getElementById("output_text");
        var data = { "input_text": $("#input_text").val() };
        e.preventDefault();
        $.ajax({
          type: 'POST',
          url: '/summarize',
          data: JSON.stringify(data),
          contentType: "application/json",
          dataType: 'json',
          beforeSend: function () {
            $("#check").attr('checked', false);
            $("#input_text").attr("readonly", true);
            $(".summarize-button").hide();
            $(".progress-icon").fadeIn();
            $("#load-noti").fadeIn();
          },
          success: function (response) {
            short_summary = response.short;
            long_summary = response.long;
            outputField.innerHTML = short_summary;
          },
          complete: function (response) {
            $("#check").attr('checked', true);
            $("#input_text").attr("readonly", false);
            $("#load-noti").text("Completed")
            runOnce = true;
          },
        })
      });

    </script>
  </body>
  <footer class="bg-light text-center text-dark mt-auto">
    <div class="container mt-3 pb-0">
      <section class="mb-3">
        <h4>Processing speed depends on the document's length</h4>
        <!-- Linkedin -->
        <!-- <a class="btn btn-sm btn-outline-light btn-floating m-1" href="#!" role="button"
          ><i class="fab fa-linkedin-in small"></i
        ></a> -->
  
        <!-- Github -->
        <!-- <a class="btn btn-sm btn-light btn-floating m-1 small" href="#!" role="button"
          ><i class="fab fa-github small"></i
        ></a> -->
      </section>
    </div>
  
    <!-- Copyright -->
    <div class="text-center p-2 bg-dark">
      <p class="text-white">
        Created by
        <a class="link-light" href="https://github.com/anhtien228" style="font-weight: 600;">Anh-Tien Doan</a>
        in 2022
      </p>
      <a class="link-secondary" href="https://flask.palletsprojects.com/en/2.1.x/" style="transition: 0.2s ease-in-out;">
        <p>built with Flask</p>
      </a>
    </div>
    <!-- Copyright -->
  </footer>
</html>