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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <!-- Bootstrap CSS -->

    <link rel="icon" type="image" href="static\social_icons\favicon.png" />
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

    <title>localGPT</title>
  </head>
  <script>
    function openFileSelection() {
      const fileInput = document.getElementById("fileInput");
      fileInput.accept = ".csv, .pdf, .txt, .doc";
      fileInput.click();
      fileInput.addEventListener("change", handleFileSelection);
    }

    function handleFileSelection(event) {
      // You can perform some checks on the files here if you want
      // Open the modal after file selection
      const uploadModal = new bootstrap.Modal(
        document.getElementById("uploadModal"),
      );
      uploadModal.show();
    }

    function submitPromptForm() {
      // Show the modal
      $("#responseModal").modal("show");

      // Submit the form after a short delay to allow the modal to open
      setTimeout(function () {
        document.getElementById("promptForm").submit();
      }, 5);
    }

    function submitForm(action) {
      var form = document.getElementById("uploadForm");

      var input = document.createElement("input");
      input.type = "hidden";
      input.name = "action";
      input.value = action;

      form.appendChild(input);

      // After the form is submitted, close the current modal and open the new one.
      $("#uploadModal").on("hidden.bs.modal", function () {
        $("#ingesting-modal").modal("show");
      });

      if (action == "add" || action == "reset") {
        $("#uploadModal").modal("hide");
      }

      form.submit();
    }
  </script>
  {% if show_response_modal %}
  <script>
    $(document).ready(function () {
      $("#response_modal").modal("show");
    });
  </script>
  {% endif %}
  <style>

    @import url('https://fonts.googleapis.com/css2?family=Play:wght@400;700&display=swap');

    body {
      background-image: linear-gradient(90deg, #09203f, #0057ff);
      height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .container{
      padding: 15px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      max-width: 1000px;
      margin: 0 auto;
    } 

    .titlegpt{
       font-size: 9vw;
       color: white;
       font-family: 'Play', sans-serif;
    } 

    .search {
      width: 100%;
      box-shadow:
        inset 0 1px 1px rgba(0, 0, 0, 0.075),
        0 0 8px rgba(255, 0, 0, 0.6);
      background-color: #fff;
      padding: 4px;
      border-radius: 5px;
    }

    ::placeholder {
      color: rgb(110, 104, 104);
      opacity: 1;
    }

    .search-2 {
      position: relative;
      width: 100%;
    }

    .search-2 input {
      height: 45px;
      border: none;
      width: 100%;
      padding-left: 100px;
      padding-right: 200px;
    }

    .search-2 input:focus {
      border-color: none;
      box-shadow: none;
      outline: none;
    }

    .search-2 i {
      position: absolute;
      top: 12px;
      left: -10px;
      font-size: 24px;
      color: #eee;
    }

    .search-2 button {
      position: absolute;
      right: 100px;
      top: 0px;
      border: none;
      height: 45px;
      background-color: #ff0059;
      color: #fff;
      width: 90px;
      border-radius: 4px;
    }

    .search-2 button:hover {
      background: #ff0059;
      color: #ffffff;
      transition: all 0.2s ease;
      cursor: pointer;
    }

    .search-2 .upload_button {
      position: absolute;
      right: 1px;
      top: 0px;
      border: none;
      height: 45px;
      background-color: #ff0059;
      color: #fff;
      width: 90px;
      border-radius: 4px;
    }

    .cancel_button {
      border: none;
      height: 45px;
      background-color: gray;
      color: #fff;
      width: 90px;
      border-radius: 4px;
    }

    .cancel_button:hover {
      background: rgb(114, 113, 113);
      color: #ffffff;
      transition: all 0.2s ease;
      cursor: pointer;
    }

    .default_button {
      border: none;
      height: 45px;
      background-color: #ff0059;
      color: #fff;
      width: 90px;
      border-radius: 4px;
    }

    .default_button:hover {
      background: #ff0059;
      color: #ffffff;
      transition: all 0.2s ease;
      cursor: pointer;
    }

    .upload_button:hover {
      background: #ff0059;
      color: #ffffff;
      transition: all 0.2s ease;
      cursor: pointer;
    }

    .search-2 .tutorial_button {
      position: absolute;
      left: 1px;
      top: 0px;
      border: none;
      height: 45px;
      background-color: #ff0059;
      color: #fff;
      width: 90px;
      border-radius: 4px;
    }

    .tutorial_button:hover {
      background: #ff0059;
      color: #ffffff;
      transition: all 0.2s ease;
      cursor: pointer;
    }

    .form-control:focus {
      border-color: #bc13cf;
      box-shadow:
        inset 0 1px 1px rgba(0, 0, 0, 0.075),
        0 0 8px rgba(255, 0, 0, 0.6);
    }

    @media (max-width: 800px) {
      .search-2 i {
        left: 4px;
      }

      .search-2 input {
        padding-left: 34px;
      }

      .search-2 button {
        height: 37px;
        top: 5px;
      }

      .search-2 .tutorial_button {
        height: 37px;
        top: 5px;
      }

      .search-2 .upload_button {
        height: 37px;
        top: 5px;
      }

      .search-2 input {
        height: 45px;
        border: none;
        width: 100%;
        padding-left: 100px;
        padding-right: 200px;
      }

      .default_button {
        height: 37px;
      }

      .cancel_button {
        height: 37px;
      }
    }

    .accordion-button:focus {
      z-index: 3;
      border-color: #ff0059;
      box-shadow: 0 0 0 0.25rem rgba(153, 50, 168, 0.25);
    }

    .accordion-button:not(.collapsed) {
      color:#ff0059;
      background-color: #f5b3cb;
      box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.125);
    }
  </style>
  <body>
    <div class="container">
      <div class="titlegpt">LocalGPT</div>
      <div class="search">
        <div class="row">
          <div class="col-md-12">
            <div class="search-2">
              <form
                id="promptForm"
                action="{{ url_for('home_page') }}"
                method="POST"
              >
                <button
                  type="button"
                  class="tutorial_button"
                  data-bs-toggle="modal"
                  data-bs-target="#tutorial_modal"
                >
                  Tutorial
                </button>
                <i class="bx bxs-map"></i>
                <input
                  type="text"
                  name="user_prompt"
                  id="searchInput"
                  placeholder="Tell a summary of what you want to know?"
                />
                <button type="button" onclick="submitPromptForm()">
                  Search
                </button>
              </form>
              <form
                id="uploadForm"
                action="{{ url_for('home_page') }}"
                method="POST"
                enctype="multipart/form-data"
              >
                <input
                  type="file"
                  name="documents"
                  id="fileInput"
                  style="display: none"
                  multiple
                />
                <button
                  type="button"
                  class="upload_button"
                  onclick="openFileSelection()"
                >
                  Upload
                </button>
              </form>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- For some reason the script needs to go here to make the the enter key also trigger the generating response modal -->
    <script>
      document
        .getElementById("searchInput")
        .addEventListener("keydown", function (event) {
          if (event.keyCode === 13) {
            event.preventDefault(); // Prevent form submission
            submitPromptForm(); // Call the function to show the modal
          }
        });
    </script>

    <!-- Chat Response Modal -->
    <div
      class="modal fade"
      id="response_modal"
      tabindex="-1"
      aria-labelledby="response_modal"
      aria-hidden="true"
    >
      <div class="modal-dialog modal-xl modal-dialog-centered">
        <div class="modal-content">
          <div class="modal-header text-center">
            <h5
              class="modal-title w-100"
              id="response_modal"
              style="color: #292b2c"
            >
              Response
            </h5>
          </div>
          <div class="modal-body text-center" style="color: #292b2c">
            <strong>Search</strong>
            <br />
            <p>{{response_dict['Prompt']}}</p>

            <strong>Answer</strong>
            <br />
            <p style="margin-left: 5%; margin-right: 5%">
              {{response_dict['Answer']}}
            </p>

            <strong>Sources</strong>
            <div
              class="accordion"
              id="accordionExample"
              style="margin-top: 10px"
            >
              {% for item in response_dict['Sources'] %}
              <div class="accordion-item">
                <h2
                  class="accordion-header text-center"
                  id="heading{{ loop.index0 }}"
                >
                  <button
                    class="accordion-button d-block text-center"
                    type="button"
                    data-bs-toggle="collapse"
                    data-bs-target="#collapse{{ loop.index0 }}"
                    aria-expanded="true"
                    aria-controls="collapse{{ loop.index0 }}"
                  >
                    {{ item[0] }}
                    <!-- Source -->
                  </button>
                </h2>
                <div
                  id="collapse{{ loop.index0 }}"
                  class="accordion-collapse collapse {% if loop.first %}show{% endif %}"
                  aria-labelledby="heading{{ loop.index0 }}"
                  data-bs-parent="#accordionExample"
                >
                  <div
                    class="accordion-body"
                    style="
                      text-align: justify;
                      margin-left: 5%;
                      margin-right: 5%;
                    "
                  >
                    {{ item[1] }}
                    <!-- Content -->
                  </div>
                </div>
              </div>
              {% endfor %}
            </div>
          </div>
          <div class="modal-footer">
            <button
              type="button"
              class="default_button"
              data-bs-dismiss="modal"
            >
              Close
            </button>
          </div>
        </div>
      </div>
    </div>

    <!-- Generating Response Modal -->
    <div
      class="modal fade"
      id="responseModal"
      tabindex="-1"
      aria-labelledby="responseModalLabel"
      aria-hidden="true"
      data-bs-backdrop="static"
      data-bs-keyboard="false"
    >
      <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
          <div class="modal-header justify-content-center">
            <h5
              class="modal-title justify-content-center"
              id="responseModalLabel"
            >
              Generating Response
            </h5>
          </div>
          <div class="modal-body text-center">
            <p>Please wait...</p>
          </div>
        </div>
      </div>
    </div>

    <!-- Upload Confirmation Modal -->
    <div
      class="modal fade"
      id="uploadModal"
      tabindex="-1"
      aria-labelledby="uploadModalLabel"
      aria-hidden="true"
    >
      <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
          <div class="modal-header justify-content-center">
            <h5
              class="modal-title justify-content-center"
              id="uploadModalLabel"
            >
              File Upload Confirmation
            </h5>
          </div>
          <div class="modal-body margin-left: 5%; text-align: left;">
            <ul>
              <li>
                Click
                <span style="background-color: #ff0059; color: white">Add</span> if
                you want to add the documents selected to your pre-existing
                knowledge base.
              </li>
              <br />
              <li>
                Click
                <span style="background-color: #ff0059; color: white">Reset</span>
                if you want to reset your knowledge base, and then use your new
                documents as your new knowledge base.
              </li>
              <br />
              <li>
                Click
                <span style="background-color: gray; color: white">Cancel</span>
                if you don't want to make any changes.
              </li>
            </ul>
          </div>
          <div class="modal-footer justify-content-center">
            <button
              type="submit"
              name="button_clicked"
              value="add_document"
              class="default_button"
              onclick="submitForm('add')"
            >
              Add
            </button>
            <button
              type="submit"
              name="button_clicked"
              value="reset_document"
              class="default_button"
              onclick="submitForm('reset')"
            >
              Reset
            </button>
            <button type="button" class="cancel_button" data-bs-dismiss="modal">
              Cancel
            </button>
          </div>
        </div>
      </div>
    </div>

    <!-- Ingesting Documents Modal -->
    <div
      class="modal fade"
      id="ingesting-modal"
      tabindex="-1"
      role="dialog"
      data-bs-backdrop="static"
      data-bs-keyboard="false"
    >
      <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
          <div class="modal-header justify-content-center">
            <h5 class="modal-title">Ingesting Documents...</h5>
          </div>
          <div class="modal-body text-center">
            <p>Please wait while we ingest the documents.</p>
          </div>
        </div>
      </div>
    </div>

    <!-- Tutorial Modal -->
    <div
      class="modal fade"
      id="tutorial_modal"
      tabindex="-1"
      aria-labelledby="tutorial_modal"
      aria-hidden="true"
    >
      <div class="modal-dialog modal-xl modal-dialog-centered">
        <div class="modal-content">
          <div class="modal-header text-center">
            <h5
              class="modal-title w-100"
              id="tutorial_modal"
              style="color: #292b2c"
            >
              Tutorial
            </h5>
          </div>
          <div class="modal-body" style="color: #292b2c">
            <strong style="margin-left: 5%; text-align: left">About</strong>
            <br />
            <p style="text-align: justify; margin-left: 5%; margin-right: 5%">
              Introducing a cutting-edge application that empowers users to
              leverage the capabilities of a language model, even in the absence
              of an internet connection. This advanced tool serves as an
              indispensable resource for accessing information beyond the
              confines of traditional language model tools such as chatGPT.
              <br /><br />
              One of the key advantages of this application is the preservation
              of data control. This feature becomes particularly valuable when
              handling sensitive data that must remain within the confines of an
              organization or personal documents that warrant utmost
              confidentiality, eliminating the need to transmit information
              through third-party channels.
              <br /><br />
              Seamlessly integrating personal documents into the system is
              effortless, ensuring a smooth user experience. Whether in the form
              of text, PDF, CSV, or Excel files, users can conveniently provide
              the desired information for inquiry. The application swiftly
              processes these documents, effectively creating a comprehensive
              database for the model to leverage, enabling accurate and
              insightful responses.
              <br /><br />
              A notable benefit of this approach lies in its efficient resource
              utilization. Unlike the resource-intensive retraining processes
              employed by alternative methods, the ingestion of documents within
              this application demands significantly less compute power. This
              efficiency optimization allows for a streamlined user experience,
              saving both time and computational resources.
              <br /><br />
              Discover the unparalleled capabilities of this technical marvel,
              as it enables users to tap into the full potential of language
              models, all while operating offline. Experience a new era of
              information access, bolstering productivity and expanding
              possibilities. Embrace this powerful tool and unlock the true
              potential of your data today.
            </p>
            <strong style="margin-left: 5%; text-align: left"
              >Upload Documents</strong
            >
            <br />
            <p
              style="
                line-height: 1.75;
                margin-left: 5%;
                margin-right: 5%;
                text-align: left;
              "
            >
              1. To upload documents for the app to ingest as its new knowledge
              base click the
              <span style="background-color: #ff0059; color: white">Upload</span>
              button.
              <br />
              2. Select the documents you want to serve as your new knowledge
              base to converse with.
              <br />
              3. Then you will be prompted with a confirmation to either
              <span style="background-color: #ff0059; color: white">Add</span> the
              documents to your knowledge base,
              <span style="background-color: #ff0059; color: white">Reset</span>
              your knowledge base with the documents you just selected, or
              <span style="background-color: gray; color: white">Cancel</span>
              the upload.
              <br />
              4. There will be a short wait time as the documents get ingested
              into the vector database as your new knowledge base.
            </p>
            <a
              href="static/document_examples/constitution.pdf"
              style="margin-left: 5%"
              download
            >
              <button class="default_button" style="width: auto">
                Example Constitution
              </button>
            </a>
            <a href="static/document_examples/news_articles.zip" download>
              <button class="default_button" style="width: auto">
                Example News Articles
              </button>
            </a>

            <br />
            <br />
            <strong style="margin-left: 5%; text-align: left">Searching</strong>
            <p
              style="
                line-height: 1.75;
                margin-left: 5%;
                margin-right: 5%;
                text-align: left;
              "
            >
              1. In order to ask a question, type a question into the search bar
              like:
              <br />
              2.
              <span style="background-color: gray; color: white"
                >Give me a summary of the documents</span
              >
              <br />
              3. Hit enter on your keyboard or click
              <span style="background-color: #ff0059; color: white">Search</span>
              <br />
              4. Wait while the LLM model consumes the prompt and prepares the
              answer.
              <br />
              5. Once done, it will print the answer and the 4 sources it used
              as context from your documents; you can then ask another question
              without re-running the script, just wait for the prompt again.
            </p>
            <br />
          </div>
          <div class="modal-footer justify-content-center">
            <button
              type="button"
              class="default_button"
              data-bs-dismiss="modal"
            >
              Close
            </button>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>